Does querySelectorAll() return live NodeList?
Answers:
No, the
querySelectorAll()method does not return a live NodeList. Instead, it returns a static NodeList, meaning that the NodeList reflects the state of the DOM at the time the method is called. If the DOM changes after the NodeList has been created (for example, if elements are added or removed that match the selector), the NodeList will not be updated to reflect those changes.For a live collection of elements, you would typically use methods such as
getElementsByTagName()orgetElementsByClassName(), which do return live NodeLists that automatically update when the DOM changes. However, it's worth noting that most modern development prefers usingquerySelector()andquerySelectorAll()for their flexibility and CSS selector support, accepting that they return static NodeLists.