Open In App
Related Articles

HTML DOM nextElementSibling Property

Improve Article
Save Article
Like Article

The nextElementSibling property is used to return the immediate next element of the specified element, in the same tree level or null if the specified element is the last one in the list. It is a read-only property. It differs from the nextSibling property as nextSibling returns the next sibling node as an element node, a text node, or a comment node while nextElementSibling returns the next sibling as an element node (i.e. it ignores text and comment nodes). 



Return value: This property returns a next sibling of the specified element or null if the current element has no next sibling. 

Example: In this example, we will use the nextElementSibling property


<!DOCTYPE html>
        DOM nextSibling Property
<body style="text-align: center">
    <h2 style="color:green;">
        DOM nextElementSibling Property
    <h4 id="h42">Web Languages:</h4>
    <select size="4">
        <option id="Select">CSS</option>
        <option>JAVA SCRIPT
    <button onclick="geek()">Next of CSS</button>
    <p id="p" style="margin:auto; width: 40%"></p>
        function geek() {
           let a =
                document.getElementById("p").innerHTML = a.text;
                document.getElementById("p").style.color = "white";
                document.getElementById("p").style.background = "green";



Supported Browsers: The browser supported by nextElementSibling property are listed below:

  • Google Chrome 2.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Opera 10.0
  • Apple Safari 4.0

Last Updated : 09 Jun, 2023
Like Article
Save Article
Similar Reads
Related Tutorials