diff options
Diffstat (limited to 'files/ja/web/api/node/comparedocumentposition')
| -rw-r--r-- | files/ja/web/api/node/comparedocumentposition/index.html | 118 | ||||
| -rw-r--r-- | files/ja/web/api/node/comparedocumentposition/index.md | 69 |
2 files changed, 69 insertions, 118 deletions
diff --git a/files/ja/web/api/node/comparedocumentposition/index.html b/files/ja/web/api/node/comparedocumentposition/index.html deleted file mode 100644 index 5865081c84..0000000000 --- a/files/ja/web/api/node/comparedocumentposition/index.html +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: Node.compareDocumentPosition -slug: Web/API/Node/compareDocumentPosition -tags: - - DOM - - DOM Element Methods - - Gecko - - Gecko DOM Reference -translation_of: Web/API/Node/compareDocumentPosition ---- -<div>{{ApiRef}}</div> - -<h2 id="Summary" name="Summary">概要</h2> - -<p>そのノードと別のノードの位置を比較し、結果となるビットマスクを返します。</p> - -<h2 id="Syntax" name="Syntax">構文</h2> - -<pre class="syntaxbox"><var>node</var>.compareDocumentPosition( <var>otherNode</var> ) -</pre> - -<h3 id="パラメーター">パラメーター</h3> - -<dl> - <dt><code>node</code></dt> - <dd>比較元ノード</dd> - <dt><code>otherNode</code></dt> - <dd><em>node</em> と比較する別ノード</dd> -</dl> - -<h3 id="返り値">返り値</h3> - -<p>呼び出し元の <code>node</code> と {{domxref("Document")}} 内の <code>otherNode</code> の関係を表すビットの整数値。複数の条件に適応する場合、1つ以上のビットがセットされることがあります。<code>compareDocumentPosition()</code> を呼び出した <code>node</code> と比較して、<code>otherNode</code> が 文書のより前にあり、かつ <code>node</code> を含んでいるならば、<code>DOCUMENT_POSITION_CONTAINS</code> と <code>DOCUMENT_POSITION_PRECEDING</code> のビットがセットされ、結果は0x0Aもしくは10進数の10になります。</p> - -<h2 id="Notes" name="Notes">注記</h2> - -<p>戻り値は以下の値を持つビットマスクの何れかとなります。</p> - -<table> - <thead> - <tr> - <th scope="col">名称</th> - <th scope="col">値</th> - </tr> - </thead> - <tbody> - <tr> - <td><code>DOCUMENT_POSITION_DISCONNECTED</code></td> - <td>1</td> - </tr> - <tr> - <td><code>DOCUMENT_POSITION_PRECEDING</code></td> - <td>2</td> - </tr> - <tr> - <td><code>DOCUMENT_POSITION_FOLLOWING</code></td> - <td>4</td> - </tr> - <tr> - <td><code>DOCUMENT_POSITION_CONTAINS</code></td> - <td>8</td> - </tr> - <tr> - <td><code>DOCUMENT_POSITION_CONTAINED_BY</code></td> - <td>16</td> - </tr> - <tr> - <td><code>DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</code></td> - <td>32</td> - </tr> - </tbody> -</table> - -<h2 id="Example" name="Example">例</h2> - -<pre class="brush:js;highlight:[3]">var head = document.getElementsByTagName('head').item(0); - -if ( head.compareDocumentPosition(document.body) & Node.DOCUMENT_POSITION_FOLLOWING ) { - console.log("head 要素は body 要素より前に記述されています。"); -} else { - console.log("head 要素は body 要素の前に配置しなくてはなりません。"); -} -</pre> - -<div class="note"> -<p><strong>注記:</strong> <code>compareDocumentPosition</code> の戻り値はビットマスクです。よって、有意な結果を得るには <a href="/ja/docs/JavaScript/Reference/Operators/Bitwise_Operators">ビット演算子</a>の "<code>&</code>" を用いなくてはならない点に注意して下さい。</p> -</div> - -<h2 id="Specification" name="Specification">仕様</h2> - -<table> - <thead> - <tr> - <th>仕様書</th> - <th>策定状況</th> - <th>コメント</th> - </tr> - </thead> - <tbody> - <tr> - <td><a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-compareDocumentPosition">DOM Level 3</a></td> - <td>Recommendation</td> - <td></td> - </tr> - <tr> - <td><a href="http://dom.spec.whatwg.org/#dom-node-comparedocumentposition">DOM Standard</a></td> - <td>Living standard</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li>{{domxref("Node.contains")}}</li> - <li><a href="http://ejohn.org/blog/comparing-document-position/">John Resig - Comparing Document Position</a></li> -</ul> diff --git a/files/ja/web/api/node/comparedocumentposition/index.md b/files/ja/web/api/node/comparedocumentposition/index.md new file mode 100644 index 0000000000..346dc65e73 --- /dev/null +++ b/files/ja/web/api/node/comparedocumentposition/index.md @@ -0,0 +1,69 @@ +--- +title: Node.compareDocumentPosition() +slug: Web/API/Node/compareDocumentPosition +tags: + - メソッド + - リファレンス +browser-compat: api.Node.compareDocumentPosition +translation_of: Web/API/Node/compareDocumentPosition +--- +{{APIRef("DOM")}} + +**`compareDocumentPosition()`** は {{domxref("Node")}} インターフェイスのメソッドで、引数のノードの位置を、呼び出されたノードからの相対位置で報告します。 + +## 構文 + +```js +compareDocumentPosition(otherNode); +``` + +### 引数 + +- `otherNode` + - : {{domxref("Node")}} で、このノードとの相対位置を報告するノードを指定します。 + +### 返値 + +整数値で、 `otherNode` の `node` から見た相対位置を、以下の {{domxref("Node")}} の定数プロパティを組み合わせた[ビットマスク](<https://ja.wikipedia.org/wiki/マスク_(情報工学)>)で表します。 + +- `Node.DOCUMENT_POSITION_DISCONNECTED` (`1`) + - : 両方のノードが、異なる文書、または同じ文書の異なるツリーにあります。 +- `Node.DOCUMENT_POSITION_PRECEDING` (`2`) + - : `otherNode` はこのノードより、両者を含むツリーの[前順深さ優先走査](https://ja.wikipedia.org/wiki/木構造_(データ構造)#深さ優先探索)で前にある(祖先ノード、前にある兄弟ノード、前にある兄弟ノードの子孫ノード、祖先ノードの前にある兄弟ノードなど)か、(接続されていないのであれば)任意だが一貫した順序で、そのノードよりも前に位置します。 +- `Node.DOCUMENT_POSITION_FOLLOWING` (`4`) + - : `otherNode` はこのノードより、両者を含むツリーの[前順深さ優先走査](https://ja.wikipedia.org/wiki/木構造_(データ構造)#深さ優先探索)で後にある(子孫ノード、後にある兄弟ノード、後にある兄弟ノードの子孫ノード、祖先ノードの後にある兄弟ノードなど)か、(接続されていないのであれば)任意だが一貫した順序で、そのノードよりも後に位置します。 +- `Node.DOCUMENT_POSITION_CONTAINS` (`8`) + - : `otherNode` はこのノードの祖先ノードです。 +- `Node.DOCUMENT_POSITION_CONTAINED_BY` (`16`) + - : `otherNode` はこのノードの子孫ノードです。 +- `Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC` (`32`) + - : その結果は、任意や実装固有の動作に依存し、移植性は保証されません。 + +複数の条件に適合する場合、複数のビットが設定されることがあります。例えば、 `otherNode` が文書中でより先にあり、**_かつ_** `compareDocumentPosition()` が呼び出されたノードを含んでいれば、 `DOCUMENT_POSITION_CONTAINS` と `DOCUMENT_POSITION_PRECEDING` の両ビットが設定され、 `10` (`0x0A`) という値になります。 + +## 例 + +```js +const head = document.head; +const body = document.body; + +if (head.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_FOLLOWING) { + console.log('正しい形式の文書です'); +} else { + console.error('<head> が <body> の前にありません'); +} +``` + +> **Note:** `compareDocumentPosition()` の返値はビットマスクですので、意味のある結果を得るには[ビット AND 演算子](/ja/docs/Web/JavaScript/Reference/Operators/Bitwise_AND)を使用する必要があります。 + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{DOMxRef("Node.contains()")}} |
