Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

DOM Node Lists

The HTML DOM NodeList Object

A NodeList object is a collection of nodes extracted from a document.

A NodeList is very similar to an HTMLCollection.

In some older browsers, methods like getElementsByClassName() return a NodeList instead of an HTMLCollection.

All browsers return a NodeList for the childNodes property.

Most browsers return a NodeList for the querySelectorAll() method.

The following code selects all <p> nodes in a document:

Example

const myNodeList = document.querySelectorAll(“p”);

The elements in a NodeList can be accessed using an index number.

To access the second <p> node, you can write:

myNodeList[1]

Note: The index begins at 0.