Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLCollection
  4. item()

HTMLCollection: item() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheHTMLCollection methoditem()returns the element located at the specified offset into the collection.

Note:Because the contents of anHTMLCollection arelive, changes to the underlying DOM can and will cause the position of individualelements in the collection to change, so the index value will not necessarily remainconstant for a given element.

Syntax

js
item(index)

Parameters

index

The position of theElement to be returned. Elements appear in anHTMLCollection in the same order in which they appear in the document'ssource.

Return value

TheElement at the specified index, ornull ifindex is less than zero or greater than or equal to the length property.

Usage notes

Theitem() method returns a numbered element from anHTMLCollection. In JavaScript, it is easier to treat theHTMLCollection as an array and to index it using array notation. See theexample below.

Examples

js
const images = document.images; // This is an HTMLCollectionconst img0 = images.item(0); // You can use the item() method this wayconst 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

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp