NodeList (W3C DOM Core object)

Spec
Version Depr.
DOM1 No
Browser support (more…)
IE5.5+ FF1.5+ SA1.3+ OP9+
Buggy Full Full Full

Example

var collection = node.childNodes;

The example above creates a reference to the childNodes collection of a Node. We could access the first item in the collection as collection[0], or collection.item(0); we could access the last item as collection[collection.length - 1], or collection.item(collection.length - 1).

We can also iterate through such a collection easily:

for(var i=0; i<collection.length; i++)
{
  doSomethingWith(collection[i]);
}

Description

The NodeList interface represents an ordered collection of nodes, indexed by number (starting from zero).

A node list is a live collection, which means that changes to the collection it represents are immediately reflected in the list (as opposed to it being a static snapshot).

CAUTION: A node list is not an array

Even though a node list looks like an array, it isn't an array — although you can iterate through it and refer to its members like an array, you can't use Array methods like push or pop on it.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Buggy Buggy Buggy Full Full Full Full Full Full Full Full

In all versions of Internet Explorer, the item method is listed as being of type string, rather than function; however it still works correctly.

In this Section

User-contributed notes

There are no comments yet.

Related Products