Static and live collections
Quick answer
querySelectorAll returns a static NodeList. A children HTMLCollection is live. A static list retains its original membership, but its elements can still change.
Browser example
Run in a browser document, not a bare Node.js process.
const root=document.createElement("div");const list=root.querySelectorAll("p");const live=root.children;root.append(document.createElement("p"));console.log(list.length,live.length);Expected console output:
0 1Common mistake
Static does not mean the contained nodes are frozen.
Practice
Take a snapshot with Array.from before removing children.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Static and live collections — Knowledge Check
Check the central concept, apply it to a new scenario, and predict browser behavior.
Which list retains its original membership after insertion?
After obtaining a live children collection, you remove one child. What happens to its length?
A static NodeList contains a paragraph whose text later changes. What does reading that same paragraph show?
Why make an Array.from snapshot of a live collection before removing each child?
What is printed by this browser snippet? (Static and live collections)
const p=document.createElement("div");p.append(document.createElement("i"));const saved=p.querySelectorAll("i"),live=p.children;p.children[0].remove();console.log(saved.length,live.length);