Favorites

DOM Document.querySelectorAll() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Document.querySelectorAll()
DOM Document MethodThis method is supported by all modern browsers.
Updated 28th November 2026

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

<label><input type="checkbox"> A</label>
<label><input type="checkbox"> B</label>
<label><input type="checkbox"> C</label>
const checks = document.querySelectorAll('input[type=checkbox]');
console.log(checks.length);
checks.forEach(c => (c.checked = true));
console.log([...checks].filter(c => c.checked).length, 'checked');

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee