MDN Web Docs

Syntax

js

item(index)

Parameters

index

The 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.

Return value

The Element 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

js

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

Specifications

Specification
DOM
# ref-for-dom-htmlcollection-item①

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗