Beginner's Guide to Coding and Data

Level: Beginner

Getting and setting data on a web page with JavaScript | Coding tutorial

video

expand_more chevron_left

text

expand_more chevron_left

Manipulating Web Pages with JavaScript

Greetings everyone! Today, we're diving deep into using JavaScript to interact with web pages. Specifically, we're going to learn how to get and set data on a web page using the JavaScript console.

Prerequisites

Before we start our journey, it's crucial to get acquainted with some basics. If you are new to JavaScript or the JavaScript console, make sure to check out the introductory lessons on CLIs earlier in the course.

  • Introduction to JavaScript Console
  • Basics of HTML Elements
  • Working with Developer Tools

Accessing Developer Tools

The first step is to access the developer tools in our browser. The quickest way is to hit F12 on the keyboard. Developer tools give us the power to peer into the underlying HTML structure of web pages.

Within the developer tools, we primarily focus on two tabs:

  • Console: for executing JavaScript code
  • Elements: to view HTML structure

Interacting with Input Elements

For this demonstration, we'll interact with the search box on the Google search page. To fetch an HTML element using JavaScript, we use the document.getElementById() method.

let searchBox = document.getElementById("input-element-id");

In the above code snippet, replace input-element-id with the actual ID of the search box element, which you can find by inspecting the element in the developer tools. Once we have the element, we can access its properties and methods using the dot operator.

Getting and Setting Data

Now, how do we actually read and modify the data inside this search box? Quite simple!

// To get the value
let currentValue = searchBox.value;

// To set the value
searchBox.value = "deeplizard";

Executing the above JavaScript code allows us to read the current text inside the search box and even modify it. How cool is that?

Wrapping Up

There we have it, folks! A real-world example of how to get and set data on web pages using JavaScript. Whether you find this easy or challenging, don't hesitate to hit the comments with your questions. And, of course, make sure to keep following the other lessons of this course.

quiz

expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Quiz Results

resources

expand_more chevron_left
Here, we will use JavaScript code in the JavaScript console πŸ’» to get and set data on a web page 🌐. 1) Web pages, Documents, Elements, Ids, getElementById πŸ–Ή 2) Verbs and Nouns 3) Getting and Setting values πŸ•’πŸ¦Ž VIDEO SECTIONS πŸ¦ŽπŸ•’ 00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources 00:30 Help deeplizard add video timestamps - See example in the description 06:36 Collective Intelligence and the DEEPLIZARD HIVEMIND πŸ’₯🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎πŸ’₯ πŸ‘‹ Hey, we're Chris and Mandy, the creators of deeplizard! πŸ‘€ CHECK OUT OUR VLOG: πŸ”— https://youtube.com/deeplizardvlog πŸ’ͺ CHECK OUT OUR FITNESS CHANNEL: πŸ”— https://www.youtube.com/channel/UCdCxHNCexDrAx78VfAuyKiA 🧠 Use code DEEPLIZARD at checkout to receive 15% off your first Neurohacker order: πŸ”— https://neurohacker.com/shop?rfsn=6488344.d171c6 ❀️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Mano Prime πŸ‘€ Follow deeplizard: Our vlog: https://youtube.com/deeplizardvlog Fitness: https://www.youtube.com/channel/UCdCxHNCexDrAx78VfAuyKiA Facebook: https://facebook.com/deeplizard Instagram: https://instagram.com/deeplizard Twitter: https://twitter.com/deeplizard Patreon: https://patreon.com/deeplizard YouTube: https://youtube.com/deeplizard πŸŽ“ Deep Learning with deeplizard: AI Art for Beginners - https://deeplizard.com/course/sdcpailzrd Deep Learning Dictionary - https://deeplizard.com/course/ddcpailzrd Deep Learning Fundamentals - https://deeplizard.com/course/dlcpailzrd Learn TensorFlow - https://deeplizard.com/course/tfcpailzrd Learn PyTorch - https://deeplizard.com/course/ptcpailzrd Natural Language Processing - https://deeplizard.com/course/txtcpailzrd Reinforcement Learning - https://deeplizard.com/course/rlcpailzrd Generative Adversarial Networks - https://deeplizard.com/course/gacpailzrd Stable Diffusion Masterclass - https://deeplizard.com/course/dicpailzrd πŸŽ“ Other Courses: DL Fundamentals Classic - https://deeplizard.com/learn/video/gZmobeGL0Yg Deep Learning Deployment - https://deeplizard.com/learn/video/SI1hVGvbbZ4 Data Science - https://deeplizard.com/learn/video/d11chG7Z-xk Trading - https://deeplizard.com/learn/video/ZpfCK_uHL9Y πŸ›’ Check out products deeplizard recommends on Amazon: πŸ”— https://amazon.com/shop/deeplizard πŸ“• Get a FREE 30-day Audible trial and 2 FREE audio books using deeplizard's link: πŸ”— https://amzn.to/2yoqWRn 🎡 deeplizard uses music by Kevin MacLeod πŸ”— https://youtube.com/channel/UCSZXFhRIx6b0dFX3xS8L1yQ ❀️ Please use the knowledge gained from deeplizard content for good, not evil.

updates

expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Update history for this page

Did you know you that deeplizard content is regularly updated and maintained?

  • Updated
  • Maintained

Spot something that needs to be updated? Don't hesitate to let us know. We'll fix it!


All relevant updates for the content on this page are listed below.