HTMLCollection: item() method
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
Parameters
-
index
-
The position of the Node to be returned. Elements appear in an HTMLCollection 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.
Examples
const images = document.images;
const img0 = images.item(0);
const img1 = images[1];
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
item |
1 |
12 |
1 |
8 |
≤12.1 |
1 |
4.4 |
18 |
4 |
≤12.1 |
1 |
1.0 |
See also