The nextSibling
property returns the node
immediately after in the same tree level as a Node object.
nextSibling |
Yes | Yes | Yes | Yes | Yes |
var v = node.nextSibling
The next sibling of the node, as a Node object.
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: