Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

この文書は翻訳中です。他国語のままの部分などがあるのはその為です。
是非お気軽に MDN に登録して翻訳に参加し、私たちの手助けをして下さい!

概要

Returns the node immediately following the specified one in its parent's childNodes list, or null if the specified node is the last node in that list.

構文

nextNode = node.nextSibling

注記

Geckoベースのブラウザはソースマークアップの中で空白を表現するためにテキストノードをドキュメントに挿入します。しかし、Node.firstChildNode.previousSibling のような例で得られるノードには、作者が取得しようとした実際の要素ではなく、空白のテキストノードが参照されます。

より多くの情報を得る為には『DOM 中の空白文字』と『W3C DOM 3 FAQ: Why are some Text nodes empty?』を参照してください。

<div id="div-01">Here is div-01</div>
<div id="div-02">Here is div-02</div>

<script type="text/javascript">
var el = document.getElementById('div-01').nextSibling;

document.write('<p>Siblings of div-01</p><ol>');

while (el) {
  document.write('<li>' + el.nodeName + '</li>');
  el = el.nextSibling;
}

document.write('</ol>');
</script>

/**************************************************
  The following is written to the page as it loads:

     Siblings of div-01

      1. #text
      2. DIV
      3. #text
      4. SCRIPT
      5. P
      6. OL
**************************************************/

In the above example, it can be seen that #text nodes are inserted in the DOM where whitespace occurs in the markup between tags (i.e. after the closing tag of an element and before the opening tag of the next). No whitespace is created between the elements inserted by the document.write statement.

The possible inclusion of text nodes in the DOM must be allowed for when traversing the DOM using nextSibling. See the resources in the Notes section.

仕様

関連情報

ドキュメントのタグと貢献者

タグ: 
 このページの貢献者: fscholz, AshfaqHossain, ethertank, Sheppy, Mgjbot, Ryotakano
 最終更新者: AshfaqHossain,