How to get the element following the specified one (next sibling) in JavaScript

1 Answer

0 votes
<div id="div-1">div-1</div>
<div id="div-2">div-2</div>
<script type="text/JavaScript">   
           
var el = document.getElementById('div-1').nextElementSibling;
console.log('Next Siblings of div-1');
while (el) 
{
    console.log(el.nodeName + '<br />');
    el = el.nextElementSibling;
}

/*
run:

Next Siblings of div-1
DIV<br / >
SCRIPT<br / >

*/

</script>

 



answered May 28, 2016 by avibootz
edited May 28, 2016 by avibootz
...