XPathResult: iterateNext()-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 iterateNext()-Methode des XPathResult-Interfaces iteriert über ein Nodeset-Ergebnis und gibt das nächste Knoten zurück oder null, wenn keine weiteren Knoten vorhanden sind.

Syntax

js
iterateNext()

Parameter

Keine.

Rückgabewert

Der nächste Node innerhalb des Nodesets des XPathResult.

Ausnahmen

TYPE_ERR

Falls XPathResult.resultType nicht UNORDERED_NODE_ITERATOR_TYPE oder ORDERED_NODE_ITERATOR_TYPE ist, wird eine XPathException vom Typ TYPE_ERR ausgelöst.

INVALID_STATE_ERR

Wenn das Dokument seit der Rückgabe des Ergebnisses verändert wurde, wird eine XPathException vom Typ INVALID_STATE_ERR ausgelöst.

Beispiele

Das folgende Beispiel zeigt die Verwendung der iterateNext()-Methode.

HTML

html
<div>XPath example</div>
<div>Tag names of the matched nodes: <output></output></div>

JavaScript

js
const xpath = "//div";
const result = document.evaluate(
  xpath,
  document,
  null,
  XPathResult.ANY_TYPE,
  null,
);
let node = null;
const tagNames = [];
while ((node = result.iterateNext())) {
  tagNames.push(node.localName);
}
document.querySelector("output").textContent = tagNames.join(", ");

Ergebnis

Spezifikationen

Specification
DOM
# dom-xpathresult-iteratenext

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
iterateNext

Legend

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

Full support
Full support