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 2015年7月.
snapshotLength は XPathResult インターフェイスの読み取り専用プロパティで、結果スナップショットのノード数を表します。
メモ: この機能はウェブワーカー内で利用可能です。
値
結果スナップショットのノード数を表す整数値です。
例外
TYPE_ERR
XPathResult.resultType が UNORDERED_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> |
ブラウザーの互換性
Loading…