A node list is a collection of nodes
The getElementsByTagName() method returns a node list. A node list is an array-like collection of nodes.
The following code selects all <p> nodes in a document:
The nodes can be accessed by an index number. To access the second <p> node you can write:
Note: The index starts at 0.
The length property defines the number of nodes in a node list:
The length property is useful when you want to loop through the nodes in a node list:
Change the background color of all <p> elements in a node list:
|A node list is not an array!
A node list may look like an array, but it is not. You can loop through the node list and refer to its nodes like an array. However, you cannot use Array Methods, like valueOf() or join() on the node list.