Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. XPathResult
  4. iterateNext()

XPathResult: iterateNext() 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⁩.

TheiterateNext() method of theXPathResult interface iterates over a node set result and returns thenext node from it ornull if there are no more nodes.

Syntax

js
iterateNext()

Parameters

None.

Return value

The nextNode within the node set of theXPathResult.

Exceptions

TYPE_ERR

In caseXPathResult.resultType is notUNORDERED_NODE_ITERATOR_TYPE orORDERED_NODE_ITERATOR_TYPE, aDOMException of typeTYPE_ERR is thrown.

INVALID_STATE_ERR

If the document is mutated since the result was returned, aDOMException of typeINVALID_STATE_ERR is thrown.

Examples

The following example shows the use of theiterateNext() method.

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(", ");

Result

Specifications

Specification
DOM
# dom-xpathresult-iteratenext

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp