HTMLCollectionNN 6 IE 5(Mac)/6(Win) DOM 1  

  

The HTMLCollection object is an abstract representation in the W3C DOM of any collection of HTML element objects, all of which exist in the same document tree and have the same tag. For example, in the eyes of the W3C DOM, the document.images array is an HTMLCollection object. All entries are img element object references. JavaScript treats such collections as arrays for access to individual entries via array notation, along with the help of the HTMLCollection's sole property, length. Alternatively, you can use the two methods (item( ) and namedItem( )) to reference a single entry in the collection. All instances of the HTMLCollection object (such as document.images) inherit the property and methods listed below from the abstract HTMLCollection object. See descriptions of each instance in this chapter (anchors, applets, areas, cells, elements, forms, images, links, options, rows, tBodies, and non-W3C DOM element collections all, children, embeds, and frames).

 
Object-Specific Properties
 
length
 
Object-Specific Methods
 
item( )namedItem( )
 
Object-Specific Event Handler Properties

None.

lengthNN 6 IE 5(Mac)/6(Win) DOM 1  

Read-only  

Returns the number of elements in the collection.

 
Example
 
var howMany = document.myForm.elements.length;
 
Value

Integer.

item( )NN 6 IE 5(Mac)/6(Win) DOM 1  

item(index)

  

Returns one object from the collection corresponding to the object matching the index value in source code order. IE implements another variation of this method for some (but not all) of its collections with an optional secondary parameter.

 
Parameters
 
index

A zero-based integer corresponding to the specified item in source code order.

 
Returned Value

Reference to an element object. If there are no matches to the parameter, the returned value is null.

namedItem( )NN 6 IE 5(Mac)/6(Win) DOM 1  

namedItem(IDOrName)

  

Returns one object from the collection corresponding to the object matching the parameter string value.

 
Parameters
 
  • The string that contains the same value as the desired filter's name.
 
Returned Value

Reference to an element object. If there are no matches to the parameters, the returned value is null.