item (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM1 | No | No |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
- Returns
Node
Example
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];
Arguments
- 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.
Description
Get a node with the specified
index (starting at zero) from a NamedNodeMap or
NodeList.
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 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.
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 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
No known issues.
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.