DOM Element.querySelectorAll() Method
The querySelectorAll() method returns a list of every element inside an element that matches a CSS selector.
Description
The querySelectorAll() method returns a static NodeList of all descendants that match the CSS selectors, in document order. Static means it's a snapshot: elements added later won't appear in it.
You can loop over the result with forEach() or for...of, but for map(), filter() and other array methods, convert it first with Array.from() or spread syntax. If nothing matches, the list is empty rather than null.
Because the search covers all descendants, a selector like 'li' also matches list items in nested lists. The :scope pseudo-class limits matches relative to the element itself, as in list.querySelectorAll(':scope > li') for direct children only.
Syntax
element.querySelectorAll(selectors)Parameters
- selectorsA string of one or more CSS selectors.
Return Value
A static NodeList of every matching descendant, which is empty if nothing matches.
Exceptions
- SyntaxErrorThrown if the selectors are not valid CSS.
Example
Browser Support
The following information will show you the current browser support for the Element.querySelectorAll() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





