MDN wants to learn about developers like you:

是非お気軽に 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;


  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,