DOM Document.querySelectorAll() Method
The document.querySelectorAll() method returns a list of every element in the page that matches a CSS selector.
Description
The querySelectorAll() method of Document returns a static NodeList of all elements in the document that match the selectors. It doesn't update as the page changes. Loop over it with forEach() or for...of, or convert it to an array for methods like map().
The list is in document order, regardless of the order of the selectors you pass, so querySelectorAll('h2, h1') still returns headings in the order they appear. Each element appears only once, even if it matches several selectors in the list.
Because it scans the whole document, keep selectors reasonably specific on very large pages, or search within a container element instead. If nothing matches, the result is an empty list, so forEach() simply does nothing.
Syntax
document.querySelectorAll(selectors)Parameters
- selectorsA string of one or more CSS selectors.
Return Value
A static NodeList of every matching element, which may be empty.
Example
Browser Support
The following information will show you the current browser support for the Document.querySelectorAll() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





