querySelector Quiz
Multiple ChoiceMedium
Question
What does `document.querySelector('#header')` return?
Hint
querySelector returns a single element (or null), not a list.
Explanation
document.querySelector('#header') returns the first element that matches the CSS selector #header (an element with id='header'). If no element matches, it returns null. To get multiple elements, use querySelectorAll (which returns a NodeList). The # prefix targets an id, just like in CSS.
Related Resources
Related Lessons
- DOM
Learn about DOM selection methods.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.