This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The HTMLCollection method item() returns the element 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 elements in the collection to change, so the index value will not necessarily remain constant for a given element.
item(index)
indexThe position of the Element to be returned. Elements appear in an HTMLCollection in the same order in which they appear in the document's source.
The Element at the specified index, or null if index is less than zero or greater than or equal to the length property.
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.
const images = document.images; // This is an HTMLCollection const img0 = images.item(0); // You can use the item() method this way const img1 = images[1]; // But this notation is easier and more common
| Specification |
|---|
| DOM> # ref-for-dom-htmlcollection-item①> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
item |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection/item