The DOM and browser events

What does querySelector return?

Examples

Worked example

Input
Selecting '#save' when the current page has no matching id.
Expected output
null

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

No element matches the selector, so the browser returns null instead of an element object.

Back to the lesson