Element.querySelectorAll() is an instance method that returns a static NodeList of every descendant matching a CSS selector—in document order. Learn MDN list patterns, forEach loops, :scope scoping, attribute selectors, Array.from(), and five try-it labs aligned with MDN.
01
Kind
Instance method
02
Finds
All descendants
03
Arg
CSS selector string
04
Returns
Static NodeList
05
Empty
length 0
06
Status
Baseline widely
Fundamentals
Introduction
Sometimes you need every match—all highlighted list items, every input in a form, or each card with a certain class. querySelector() only gives you the first result; querySelectorAll() collects them all.
querySelectorAll(selectors) returns a static (non-live) NodeList of matching descendant elements (MDN). Results stay in document order: parents before children, earlier siblings before later ones.
💡
Beginner tip
No matches returns an empty NodeList (length === 0), not null. Check list.length before looping. For array methods like map, use Array.from(list) (MDN).
Element.querySelectorAll() is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.querySelectorAll()
Get all matching descendants as a static NodeList — in document order.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet Explorer8+ · IE8 with limitations
Yes
querySelectorAll()Excellent
Bottom line: Use querySelectorAll() when you need every match inside an element. Pair with forEach or Array.from() for batch updates.
Wrap Up
Conclusion
Element.querySelectorAll() collects every matching descendant in a static NodeList. Loop with forEach, check length for empty results, and prefix with :scope when you need true scoped matching.
Convert with Array.from() when you need array methods
Prefix with :scope to limit selector scope (MDN)
Escape dynamic ids with CSS.escape()
❌ Don’t
Expect null—no match means empty NodeList
Assume the NodeList stays in sync with DOM changes (it is static)
Use querySelectorAll when one match is enough
Call map directly on NodeList without converting
Include pseudo-element selectors if you expect results (always empty per MDN)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.querySelectorAll()
Every matching descendant in document order.
5
Core concepts
📝01
Returns
NodeList
Static
📄02
Empty
length 0
Not null
✍️03
Loop
forEach
MDN
✅04
Baseline
since 2015
Status
⚡05
Scope
:scope
MDN
❓ Frequently Asked Questions
It returns a static NodeList of all descendant elements that match the specified CSS selectors (MDN).
No. MDN marks Element.querySelectorAll() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
A static (non-live) NodeList of matching Element objects in document order, or an empty NodeList when nothing matches (MDN).
querySelectorAll() returns every match in a NodeList. querySelector() returns only the first match as an Element or null.
MDN: querySelectorAll() returns a static NodeList — it does not update when the DOM changes after the call.
A SyntaxError DOMException is thrown if selectors is not a valid CSS selector string (MDN).
Did you know?
MDN notes that querySelectorAll() returns a static NodeList—unlike older live collections from getElementsByClassName, it does not auto-update when the DOM changes after your call.