π INDEX
LOADING ENGINE...
JS Element Access
Learn to capture and manipulate DOM elements with modern JavaScript.
element_access.js
1 / 3
π
Exploring the DOM...
Tutor: To access elements in the DOM, we use the 'document' object. The fastest method is getElementById().
Key Concepts
getElementById()Searches for a unique element through its ID attribute. It is the most efficient method.
querySelector()Uses CSS selectors. Returns the first matching element.
querySelectorAll()Returns a NodeList (similar to an array) with all matching elements.
Code Mission
Write the code to get an element with the id "btn-save":
Tip: Check the parentheses and quotes.
Access Glossary
- NodeList
- Collection of nodes returned by querySelectorAll. Can be iterated with .forEach().
- Live Collection
- Collections (like those from getElementsByTagName) that automatically update if the DOM changes.
- HTMLElement
- The type of object that represents an HTML element in JavaScript.