JavaScript JavaScript and the DOM Responding to User Interaction Listening for Events with addEventListener()

Amandeep Pasricha
Amandeep Pasricha
14,928 Points

What's the difference between a node list and an HTML collection? Are you able to loop through one and not the other?

As asked.

2 Answers

Steven Parker
Steven Parker
172,034 Points

These are both iterables (loopable). The big difference is that a node list is a static structure, much like an array, where an HTMLCollection is "live" and will change along with any changes made to the DOM.

Amandeep Pasricha
Amandeep Pasricha
14,928 Points

Steven Parker Oh okay so is the nodelist the real HTML that you can't change, while the HTML collection is part of the DOM?

Steven Parker
Steven Parker
172,034 Points

You can change a NodeList, it just doesn't automatically change when you do things to the DOM.