The item()
method of the HTMLAllCollection
interface returns the element located at the specified offset into the collection, or the element with the specified value for its id
or name
attribute.
The item()
method of the HTMLAllCollection
interface returns the element located at the specified offset into the collection, or the element with the specified value for its id
or name
attribute.
js
item(nameOrIndex)
nameOrIndex
If this parameter is an integer, or a string that can be converted to an integer, then it represents the position of the Element
to be returned. Elements appear in an HTMLAllCollection
in the same order in which they appear in the document's source. If the parameter is a string can't be converted to an integer, it will be interpreted as the name
or id
of the element to be returned.
If nameOrIndex
represents an index, item()
returns the Element
at the specified index, or null
if nameOrIndex
is less than zero or greater than or equal to the length property. If nameOrIndex
represents a name, item()
returns the same value as namedItem()
.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
item |
5 | 12 | 32 | 11 | 15 | 5 | 3 | 18 | 32 | 14 | 4 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLAllCollection/item