Targeting HTML Elements
Master JavaScript DOM Manipulation with Chrome DevTools
Core Skills You'll Master
Chrome DevTools Mastery
Learn to inspect, debug, and experiment with HTML elements using professional developer tools. Essential for any web developer's toolkit.
DOM Element Selection
Master the getElementById() method to precisely target and manipulate specific HTML elements in your web pages.
Dynamic Property Control
Gain the ability to get and set element properties, values, and styles programmatically using JavaScript.
This hands-on exercise teaches JavaScript DOM manipulation through Chrome's DevTools Console. You'll learn to select, modify, and control HTML elements dynamically without writing permanent code.
DevTools Setup Process
Open File in Chrome
Navigate to form.html in the Form-Fields folder and open with Google Chrome browser
Launch DevTools
Right-click anywhere on the page and select 'Inspect' from the context menu
Explore Elements Panel
Use the Elements tab to inspect HTML markup and hover over elements to see highlights
Access Console
Switch to the Console tab where you'll execute JavaScript commands for testing
Use the element selector button in DevTools to click on page elements and automatically highlight their corresponding HTML code. This makes it easy to find the exact markup you want to modify.
The Console displays <input id="nameField … value="First and Last Name">, representing the complete element object.
Hover over this output and notice that only the nameField input highlights in the webpage. This confirms successful element selection. We can now access this element's properties and methods using JavaScript's dot notation syntax—a pattern you'll use constantly in professional development.
Extend the previous command by adding the following bold code:
document.getElementById('nameField').style.display = 'none';
This statement chains two operations: first, it selects the element with ID nameField, then accesses its CSS display property and sets it to 'none', effectively hiding the element. Note that CSS property values must be provided as strings in JavaScript.
Modify the display value as shown in bold:
document.getElementById('nameField').style.display = 'block';Press Return (Mac) or Enter (Windows). The input reappears, confirming your ability to control element visibility programmatically.
The method must be written as getElementById() with exact capitalization. Writing getElementByID() with capital 'ID' will cause the function to fail completely.
getElementById() Method Analysis
Getting vs Setting Element Values
| Feature | Getting Values | Setting Values |
|---|---|---|
| Syntax | element.value | element.value = 'new text' |
| Purpose | Read current content | Write new content |
| Return Value | Current string value | Updated element |
| Use Case | Form validation | Dynamic updates |
Value Manipulation Workflow
Select Target Element
Use document.getElementById() to target the specific input field you want to work with
Access Value Property
Add .value to read the current content or assign new content with = operator
Test Changes
Execute commands in Console to see immediate results and verify your code works correctly
Changes made in the Console are temporary and lost on page reload. This makes it perfect for testing code safely before implementing permanent solutions in your JavaScript files.
Key Takeaways

element selector button. This activates inspection mode—when you hover over any element in the actual webpage, the corresponding HTML code highlights automatically in DevTools, streamlining the process of locating specific elements in complex documents.