querySelector()
The DOM method that returns the first element matching a CSS selector, or null if nothing matches.
In more detail
It can be called on the document or on any element to search only inside it. Because it uses normal CSS selector syntax, anything you can style you can also find.
Related terms
- querySelectorAll() — The DOM method that returns every element matching a CSS selector as a static NodeList.
- CSS selector — A pattern, such as .card, #menu or nav a, that picks which elements a CSS rule applies to or which elements a DOM query returns.
- Element.closest() — The DOM method that starts at an element and walks up through its ancestors, returning the first one, itself included, that matches a selector.
- null — A special value meaning no value or no object, set on purpose to show that something is empty or absent.
Taught in
- Semantic HTML Elements: Landmarks And Structure — Frontend Architecture & Web Platform
- Modern DOM Querying: querySelector, closest And matches — Frontend Architecture & Web Platform
- Modern Selectors: :has(), :is(), :where() And Nesting Standards — Frontend Architecture & Web Platform