Element.nextElementSibling

Table of contents

  1. 1. Summary
  2. 2. Syntax and values
  3. 3. Example
  4. 4. See also
Table of contents
  1. 1. Summary
  2. 2. Syntax and values
  3. 3. Example
  4. 4. See also

Introduced in Gecko 1.9.1

(Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

« Gecko DOM Reference

Summary

nextElementSibling returns the element immediately following the specified one in its parent's children list, or null if the specified element is the last one in the list.

Syntax and values

var nextNode = elementNodeReference.nextElementSibling; 

nextNode is a reference to the next sibling of the element node, or null if there isn't one.

This attribute is read-only.

Example

<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').nextElementSibling;
  document.write('<p>Siblings of div-01</p><ol>');
  while (el) {
    document.write('<li>' + el.nodeName + '</li>');
    el = el.nextElementSibling;
  }
  document.write('</ol>');
</script>

This example outputs the following into the page when it loads:

Siblings of div-01

   1. DIV
   2. SCRIPT
   3. P
   4. OL

Tags (2)

Edit tags

Attachments (0)

 

Attach file