Find and inspect live page elements.
- querySelector
- querySelectorAll
- Element
- NodeList
The DOM represents the parsed document as objects. querySelector returns the first match or null; querySelectorAll returns a static collection of matches. A selector is a CSS selector string, so choose stable classes or data attributes rather than fragile ancestry.
Calling a method on null throws when the selector matches nothing.
Select a heading, button, and list; print their text and count, then deliberately test a missing selector.
Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.
- Explain the core idea in your own words without reading the code.
- Change one input and predict the output before running it.
- Test one boundary or failure case, then record what you changed.