Table of contents
- 1. Summary
- 2. Syntax and values
- 3. Example
- 4. See also
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
Mozilla Developer Network