JavaScript JavaScript and the DOM Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

3 Answers

Steven Parker
Steven Parker
177,482 Points

A "node" is a single point on the DOM tree. All elements are nodes, but nodes can also contain things that are not elements.

An "HTMLCollection" is a group of elements, always in document order. It is also always "live", meaning changes made to the DOM will be immediately reflected in the contents of the collection.

A "nodeList" is a collection of nodes, which as mentioned may include elments and/or other things. Depending on how it was obtained it might be "live", but check the documentation before assuming that.

Both are array-like but they are not actual arrays. They share some array methods but not all.

For more details, see the MDN pages on HTMLCollection and NodeList.

Tim Abbott
Tim Abbott
13,323 Points

Thanks, very useful.

guram dgebuadze
guram dgebuadze
Front End Web Development Techdegree Student 4,121 Points

In the links you shared here is written: ''Although NodeList is not an Array, it is possible to iterate over it with forEach(). It can also be converted to a real Array using Array.from().'' But there was nothing said about this in video lectures, also I work without problem in arrays and what's the problem, differenece?

Steven Parker
Steven Parker
177,482 Points

As you pointed out, "forEach" is a good example of a method they have in common. But arrays have many methods that these don't, such as "reverse", "sort", "slice", "push", etc. For more details, compare the methods in the links above to the ones for the array prototype.