Collection.Item() (Method)

Select an Element object by index number.


DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Opera - 5.0
Property/method value type:Node object
JavaScript syntax:-myCollection.item(anIndex)
-myCollection.item(aSelector, anIndex)
Argument list:anIndexA zero based index into the collection
aSelectorA textual value that selects all matching objects

This is a search method that traverses a collection looking for an item or collection of items by the index in the collection.

If the first argument is a numeric value, the object at the indexed position is returned. You may not place a second argument in the call. This is the DOM standard specified behavior.

If the first argument is a string, then any object in the collection that has an id or name property that matches the selector will be assembled into another collection. If there is no second argument, that new collection will be returned as a sub-set of the original receiving collection. This is an extension to the DOM specified behavior.

If the first argument is a string and the second argument is a numeric value, the sub-set collection is manufactured but the element in that collection indexed by the second argument is returned as a single object. This is also an extension to the DOM specified behavior.

This extension is useful because you can apply a filter and selection in one call without needing to extract and then store a sub-set collection. On the downside, this will repeat the sub-setting search each time it is called which can lead to performance problems.

When using the myCollection.item(anIndex) syntax variation, it is functionally equivalent to myCollection[anIndex].

Note that the DOM specification does not allow for the alternative array-like addressing mode which is implemented in browsers as a convenience.


See also:Collection object, NamedNodeMap.item(), OptionsArray.item(), style.item()