Javascript Reference - HTML DOM nextSibling Property








The nextSibling property returns the node immediately after in the same tree level as a Node object.

Browser Support

nextSibling Yes Yes Yes Yes Yes

Syntax

var v = node.nextSibling

Return Value

The next sibling of the node, as a Node object.





Example

The following code shows how to get the next sibling of a list item.


<!DOCTYPE html>
<html>
<body>
<p id="demo">test</p>
<button onclick="myFunction()">test</button>
<!--   w  w w.  j  a v a 2 s .c  o  m-->
<script>
function myFunction()
{
    var x=document.getElementById("demo");  
    x.innerHTML=document.getElementById("item1").nextSibling.id;
}
</script>
</body>
</html>

The code above is rendered as follows: