showing results for - "nextsibling vs nextelementsibling"
Amy
16 Oct 2017
1// nextElementSibling always returns an element. 
2// nextSibling can return any kind of node.
3// They are the same for your example, but different in other
4<p>
5  <span id="span-01">Here is span-01</span>
6  Some text at the top level
7  <span id="span-02">Here is span-02</span>
8</p>
9document.getElementById('span-01').nextElementSibling //is  span-02
10document.getElementById('span-01').nextSibling // is the text node containing 
11											  //  "Some text at the top level" 
12//note:
13//
14<div id="div-1">Here is div-1</div> 
15<div id="div-2">Here is div-2</div>
16var el = document.getElementById('div-1').nextSibling // is #text node
17var el2 = document.getElementById('div-2').nextSibling // is #text node
18//text nodes are inserted in the DOM where whitespace occurs between tags
19//(i.e. after the closing tag of an element and before the opening tag of the next).
20//source : https://developer.mozilla.org/en-US/docs/Web/API/Node/nextSibling#example
21