Javascript examples for DOM:Element nextElementSibling
The nextElementSibling property returns the element immediately following the specified element with the same parent.
This property is read-only.
A Node object, representing the next sibling of an element, or null if there is no next sibling
The following code shows how to get the HTML content of the next sibling of a list item:
<!DOCTYPE html> <html> <body> <p>Example list:</p> <ul> <li id="item1">(first li)</li> <li id="item2">(second li)</li> </ul>/*w w w. j a v a 2 s . c o m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("item1").nextElementSibling.innerHTML; document.getElementById("demo").innerHTML = x; } </script> </body> </html>