return elements that match specified CSS selector(s)

Is NodeList returned by querySelectorAll live or static?

Answers:

  • The NodeList returned by querySelectorAll is static. This means that it represents a snapshot of the DOM at the moment the method is called. If the DOM changes after the NodeList is created (for example, if nodes are added or removed), the NodeList will not update to reflect those changes.

    In contrast, a "live" NodeList, such as those returned by properties like getElementsByTagName or getElementsByClassName, automatically updates when the DOM is modified.

    So, to summarize: the NodeList from querySelectorAll does not change if the DOM changes after it is obtained.