Returns a node from a NodeList by index. This method doesn't throw exceptions as long as you provide arguments. A value of null is returned if the index is out of range, and a TypeError is thrown if no argument is provided.

句法

nodeItem = nodeList.item(index)
					
  • nodeList NodeList . This is usually obtained from another DOM property or method, such as childNodes .
  • index is the index of the node to be fetched. The index is zero-based.
  • nodeItem index th node in the nodeList 返回通过 item 方法。

Alternate Syntax

JavaScript also offers an array-like bracketed syntax for obtaining an item from a NodeList by index:

nodeItem = nodeList[index]
					

范例

var tables = document.getElementsByTagName("table");
var firstTable = tables.item(1); // or simply tables[1] - returns the second table in the DOM
					

规范

规范 状态 注释
DOM
The definition of 'NodeList: item' in that specification.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
item Chrome 1 Edge 12 Firefox Yes IE ? Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: