NamedNodeMap: item()-Methode

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.

Die item()-Methode der NamedNodeMap-Schnittstelle gibt das Element in der Map zurück, das dem Index entspricht.

Hinweis: Diese Methode wird auch aufgerufen, wenn Sie die Operator-[]-Syntax verwenden. Also ist myMap[i] gleichwertig zu myMap.item(i), wobei i eine Zahl ist.

Syntax

js
item(index)
[index]

Parameter

index

Eine Zahl, die den Index des Elements darstellt, das Sie zurückgeben möchten.

Rückgabewert

Ein Attr oder null, wenn die Zahl größer oder gleich der length der Map ist.

Beispiel

html
<pre zero="test" one="test" two="test"></pre>
js
const pre = document.querySelector("pre");
const attrMap = pre.attributes;

pre.textContent = `The attribute map contains:
0: ${attrMap.item(0).name}
1: ${attrMap[1].name}
2: ${attrMap.item(2).name}`;

Spezifikationen

Specification
DOM
# dom-namednodemap-item

Browser-Kompatibilität

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