NodeList (W3C DOM Core object)
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).
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.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.




