NodeList: item() メソッド

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.

NodeList からインデックスでノードを返します。このメソッドは引数を提供する限り例外を発生しません。インデックスが範囲外の場合は null という値が返され、引数が指定されなかった場合は TypeError が発生します。

構文

js
item(index)

JavaScript では、NodeList からインデックスでアイテムを取得するのに配列風の括弧構文も提供しています。

js
nodeItem = nodeList[index];

引数

  • index はノードを読み取るインデックスです。インデックスはゼロ基点です。

返値

item メソッドが返す nodeList 内の index 番目のノード。

例外

TypeError

引数が提供されなかった場合に発生します。

js
const tables = document.getElementsByTagName("table");
const firstTable = tables.item(1); // または tables[1] - DOM 内の 2 番目の表を返す

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
item

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support