XPathResult: snapshotLength プロパティ

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.

snapshotLengthXPathResult インターフェイスの読み取り専用プロパティで、結果スナップショットのノード数を表します。

メモ: この機能はウェブワーカー内で利用可能です。

結果スナップショットのノード数を表す整数値です。

例外

TYPE_ERR

XPathResult.resultTypeUNORDERED_NODE_SNAPSHOT_TYPE または ORDERED_NODE_SNAPSHOT_TYPE でない場合、 TYPE_ERR 型の XPathException が発生します。

次の例では snapshotLength プロパティを使用しています。

HTML

html
<div>XPath example</div>
<div>Number of matched nodes: <output></output></div>

JavaScript

js
const xpath = "//div";
const result = document.evaluate(
  xpath,
  document,
  null,
  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  null,
);
document.querySelector("output").textContent = result.snapshotLength;

結果

仕様書

Specification
DOM
# dom-xpathresult-snapshotlength

ブラウザーの互換性

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
snapshotLength

Legend

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

Full support
Full support