Favorites

DOM Element.querySelectorAll() Method

☕
Enjoying this site?

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

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

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

<nav>
  <a href="#">Home</a>
  <a href="#">Blog</a>
  <a href="#">Contact</a>
</nav>
const nav = document.querySelector('nav');
const links = nav.querySelectorAll('a');
console.log(links.length);
links.forEach(a => a.style.fontWeight = 'bold');
console.log([...links].map(a => a.textContent));
console.log(nav.querySelectorAll('.missing').length);

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.

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