item (W3C DOM Core method)

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


var divs = document.getElementsByTagName('div');

var first = divs.item(0);

The example above gets the collection of div elements on the current page, then saves the first item in that collection to the first variable. If that element exists then first will be a reference to it, otherwise it will be null.

That example could also be written using the array syntax:

var first = divs[0];


index (unsigned long) required

The index of the item to retrieve. If the index is greater than or equal to the length of the collection, this method will return null.


Get a node with the specified index (starting at zero) from a NamedNodeMap or NodeList.

Tip: item is more reliable than array syntax

In rare cases an implementation might not support the array syntax — for example, the DOM implementation in some versions of Adobe's SVG plugin does not. So it's safer to use item.

Note: item may return differently than array syntax

Note also that the return value of an non-existent item is different for the different forms of syntax — item will return null, where the array syntax will return undefined.

Return value

The node (of any type) at the specified index in the collection ; or null if the index is not valid.


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
Full Full Full Full Full Full Full Full Full Full Full

No known issues.

User-contributed notes

There are no comments yet.

Related Products