JavaScript

Query Selector

Definition

`document.querySelector()` returns the first element matching a CSS selector. `querySelectorAll()` returns all matching elements as a NodeList. These are the modern replacements for `getElementById` and `getElementsByClassName`.

Code Example

Javascript
Tip: Modify the code above and click “Run” to see the results

Learn More

Related Terms