document.querySelectorAll(selectors) returns a static (not live) NodeList of every Element that matches a CSS selector (or group of selectors). Matches are in document order. No matches → an empty list, not null.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.querySelectorAll. Start with this line.
JavaScript
document.querySelectorAll(selectors)
Call
What it does
document.querySelectorAll(selectors)
Primary signature.
document.querySelectorAll(...)
Call with the arguments your case needs.
Built into the browser. Call querySelectorAll(...) on document — no import required.
Library declarations
JavaScript
document.querySelectorAll(selectors)
Parameters
Parameter
Description
selectors
Required. Valid CSS selector string
Return Value
Return Value
Description
*
Static NodeList (empty if none)
JavaScript Examples
Example 1 — All <p> Elements
MDN-style: collect every paragraph in the document.
JavaScript
const matches = document.querySelectorAll("p");
console.log(matches.length);
// number of <p> elements
console.log(matches[0] ? matches[0].textContent : "(none)");
It returns a static (not live) NodeList of every Element in the document that matches the given CSS selector or group of selectors.
No. MDN marks Document.querySelectorAll() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
You get an empty NodeList (length 0), not null. forEach still works — it simply runs zero times.
It is static (non-live). It does not automatically update when the DOM changes after the call.
querySelector() returns the first matching Element or null. querySelectorAll() returns every match in a NodeList (empty when none).
A SyntaxError DOMException is thrown if selectors is not a valid CSS selector string. Escape special class/id values with CSS.escape().