Research-documentation Week 3 - HTMLCollection and NodeList

Definition of the HMTLCollection

The HTMLCollection is an interface that act as a general collection of elements. This is a lot like an array. This interface gives you the ability to use methods and properties for selecting from the list. For example, you can use HTMLCollection.length to get the number of items in the collection. The HTMLCollection in the HTML DOM is live. This means that it automatically changes when the document is modified.

Definition of the NodeList

A NodeList is also quite like an array in that you can loop through it and retrieve its nodes by index, but it is not exactly an array. There are several Array methods that cannot be used on a NodeList like join() or pop(). The NodeList is essentially a list of nodes extracted from a document.

Differences and/or Similarities

A NodeList is like an HTMLCollection in that they are both array-like collections. The nodes are the elements in the “array” that can be accessed using its index number. They both have a length property that can be used to retrieve the number of elements from the collection/list. Unlike an HTMLCollection, NodeList nodes can only be retrieved using their index number, while HTMLCollection elements can be retrieved using their name, id, or index number. Another difference is that the HTMLCollection is always live which means that it is updated as it gets changed and the NodeList is static which means it will not change.

Summary of Documentation

The NodeList and HTMLCollection are very similar and there are minor differences between them. One of the most important things to remember is a NodeList is static while the HTMLCollection is dynamic. Both have their own sets of properties and methods that can be used to manipulate and access their nodes or elements inside them.