From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../ja/web/api/xpathresult/snapshotitem/index.html | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 files/ja/web/api/xpathresult/snapshotitem/index.html (limited to 'files/ja/web/api/xpathresult/snapshotitem') diff --git a/files/ja/web/api/xpathresult/snapshotitem/index.html b/files/ja/web/api/xpathresult/snapshotitem/index.html new file mode 100644 index 0000000000..832a306960 --- /dev/null +++ b/files/ja/web/api/xpathresult/snapshotitem/index.html @@ -0,0 +1,85 @@ +--- +title: XPathResult.snapshotItem() +slug: Web/API/XPathResult/snapshotItem +tags: + - API + - DOM XPath API + - Method + - Reference + - XPath + - XPathResult + - メソッド +translation_of: Web/API/XPathResult/snapshotItem +--- +
{{APIRef("DOM XPath")}}
+ +

snapshotItem() は {{domxref("XPathResult")}} インターフェイスのメソッドで、アイテムのスナップショットのコレクション、または添字がノードの範囲を外れている場合は null を返します。イテレーターの返値とは異なり、スナップショットは無効になることはありませんが、変更したときに現在の文書に対応しない場合があります。

+ +

構文

+ +
var node = result.snapshotItem(i);
+
+ +

返値

+ +

XPathResult のノードセット内の指定された添字の {{domxref("Node")}} です。

+ +

例外

+ +

TYPE_ERR

+ +

{{domxref("XPathResult.resultType")}} が UNORDERED_NODE_SNAPSHOT_TYPE または ORDERED_NODE_SNAPSHOT_TYPE でない場合、 {{domxref("XPathException")}} による例外が TYPE_ERR 型で発生します。

+ +

+ +

以下の例は snapshotItem() メソッドの使用例を表しています。

+ +

HTML

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

JavaScript

+ +
var xpath = "//div";
+var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+var node = null;
+var tagNames = [];
+for(var i = 0; i < result.snapshotLength; i++) {
+  var node = result.snapshotItem(i);
+  tagNames.push(node.localName);
+}
+document.querySelector("output").textContent = tagNames.join(", ");
+
+ +

結果

+ +

{{EmbedLiveSample('Example', 400, 70)}}

+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("DOM3 XPath", "xpath.html#XPathResult-snapshotItem", "XPathResult.snapshotItem()")}}{{Spec2("DOM3 XPath")}}初回定義
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("api.WindowOrWorkerGlobalScope.clearTimeout")}}

+
-- cgit v1.2.3-54-g00ecf