The HTMLCollection
method item()
returns the node located at the specified offset into the collection.
Note: Because the contents of an HTMLCollection
are live, changes to the underlying DOM can and will cause the position of individual nodes in the collection to change, so the index value will not necessarily remain constant for a given node.
Syntax
var element = HTMLCollection.item(index)
Parameters
index
- The position of the
Node
to be returned. Elements appear in anHTMLCollection
in the same order in which they appear in the document's source.
Return value
The Node
at the specified index, or null
if index
is less than zero or greater than or equal to the length property.
Usage notes
The item()
method returns a numbered element from an HTMLCollection
. In JavaScript, it is easier to treat the HTMLCollection
as an array and to index it using array notation. See the example below.
Example
var c = document.images; // This is an HTMLCollection
var img0 = c.item(0); // You can use the item() method this way
var img1 = c[1]; // But this notation is easier and more common
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
item
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support Yes |
IE
? |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
See also
HTMLCollection.item by Mozilla Contributors is licensed under CC-BY-SA 2.5.