The DOM & Getting/Setting Properties
Master DOM Manipulation with JavaScript GetElementById
Core DOM Concepts You'll Master
Element Selection
Learn to target specific HTML elements using GetElementById() method. This is the foundation of DOM manipulation.
Property Manipulation
Discover how to get and set element properties like src, display, and classList to create dynamic interactions.
Visual Feedback
Implement user interface changes like border colors and image swapping to provide immediate visual feedback.
Product Color Picker Development Process
Setup Environment
Configure your development environment with proper folder structure and browser DevTools access
Element Selection
Master the GetElementById() method to target specific HTML elements in your webpage
Property Manipulation
Learn to modify element properties including images, styles, and CSS classes dynamically
Visual Implementation
Apply changes to create a functional color picker with proper user feedback mechanisms
You should see <img id="product-photo" src="img/chair-beige.jpg"> returned in the Console. This represents the actual DOM element object.
Hover over this output and notice that only the product image highlights in the webpage. You've successfully selected a specific element from the page structure. Now you can access and modify this element's properties using dot notation.
Modify the command by appending the following code:
document.getElementById('product-photo').style.display = 'none';
This command demonstrates CSS property manipulation through JavaScript. You're accessing the element's style object and setting its display property to 'none', which will hide the element completely. Note that CSS property values must always be strings in JavaScript.
Modify the display value as shown:
document.getElementById('product-photo').style.display = 'block';Execute the command to restore the image visibility.
These Console experiments provide immediate feedback and are invaluable for testing code snippets before implementing them in your actual JavaScript files. While Console changes are temporary (they reset when you refresh the page), this testing approach prevents errors in your production code.
Keep this browser tab open—you'll need to reload the page to test the permanent code changes you'll make next.
Project File Structure
CSS Class vs Inline Style Approach
| Feature | classList.add() | style.property |
|---|---|---|
| Code Maintainability | High - CSS separate | Lower - Mixed concerns |
| Developer Collaboration | Easy for CSS devs | Requires JS knowledge |
| Multiple Properties | One line of code | Multiple JS lines |
| Performance | Better - cached CSS | Direct DOM updates |
JavaScript in the head section fails because it executes before HTML elements are created. Always place scripts at the bottom of the body for reliable element access.
Property Manipulation Implementation
Element Storage
Store selected elements in variables using let productPhoto = document.getElementById('product-photo')
Property Updates
Modify properties like productPhoto.src = 'img/chair-red.jpg' to change image sources
Class Management
Use classList.add('selected') to apply pre-defined CSS classes for styling
Key Takeaways

element selector button in the top-left corner. This tool lets you click any page element to inspect its HTML.