Javascript Reference
Categories: NodeList

javascript NodeList Description

@Aug. 17, 2009, 9:09 a.m.
NodeList Firefox/Netscape/NN 6 IE 5 Chrome/Safari/DOM 1  



The NodeList object is an abstract representation in the W3C DOM of a collection of nodes of any type. Any W3C DOM property or method that returns a collection of nodes returns an object of type NodeList. For example, the Node object's childNodes property and the Element object's getElementsByTagName( ) method both return NodeList objects. JavaScript exposes a NodeList collections as an array that has the familiar length property. Scripts can reference individual items in the array through integer array indexes (inside square brackets) or via the NodeList object's item( ) method.


Some node types have their own collections (e.g., NamedNodeMap for a collection of attribute nodes and the HTMLCollection for a collection of HTML element nodes). These other collection objects have extra properties and methods that are meaningful only to the types of nodes inside the collections. For instance, because text nodes (one of the simplest type of Node object) do not have a property that can contain an identifier, the NodeList object does not include a method to reference an item by its ID. But an HTMLCollection object (consisting entirely of the more complex HTMLElement types of nodes) includes another method (namedItem( )) that lets scripts reference an item by its ID as well as integer index. The distinctions among collection object types are readily apparent when you compare the properties and methods of the collection objects you actually script (see the descriptions of the attributes and images objects, for example). The W3C DOM terminology, on the other hand, is not a factor in scripts.

Powered by Linode.