Course contentsShow
← Web Development
Lesson 669 of 2,98212. The Document Object ModelFree lesson

Live vs Static NodeLists

The difference between collections that update automatically and static snapshots of the DOM.

Live vs Static NodeLists

You'll learn: the crucial difference between DOM collections that update automatically when the page changes and those that remain frozen in time.


When you query the DOM for elements, JavaScript returns a collection of nodes—but not all collections behave the same way. Some are live, meaning they automatically reflect changes to the DOM in real-time, while others are static snapshots that capture the DOM's state at the moment you queried it.

What Makes a NodeList "Live"?

A live NodeList is like a window looking directly at the DOM tree. If elements matching your original query are added or removed from the page, the collection automatically updates. You're not holding a copy—you're holding a reference to something dynamic.

What Makes a NodeList "Static"?

A static NodeList is like a photograph of the DOM at one specific moment. Even if the DOM changes afterward, your collection stays exactly as it was when you first created it. The list won't grow or shrink.

Why This Matters

Imagine you grab a collection of elements, then loop through them while modifying the DOM. If your collection is live, it can change while you're iterating, potentially causing unexpected behavior or infinite loops. If it's static, you're safe—your loop works with a fixed set.

Which Methods Return Which Type?

The methods you use determine what you get:

  • Live collections: Typically returned by older methods like getElementsByTagName() or getElementsByClassName()
  • Static collections: Returned by modern methods like querySelectorAll()

Key Takeaway: Live NodeLists update automatically when the DOM changes; static NodeLists are frozen snapshots. Knowing which type you're working with prevents confusing bugs during DOM manipulation.