return elements that match specified CSS selector(s)

Is NodeList static or live when using querySelectorAll()?

Answers:

  • The NodeList returned by querySelectorAll() is static. This means that it is a snapshot of the elements that match the specified selector at the time the method is called. If the DOM changes after the NodeList is created (for example, if elements are added or removed), those changes will not be reflected in the NodeList.

    In contrast, a live NodeList would automatically update to reflect changes in the DOM. An example of a live NodeList is the one returned by methods like getElementsByTagName() or getElementsByClassName().

Related Questions: