Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM isSameNode() Method

  • Last Updated : 25 Jul, 2019

The isSameNode() method checks whether the two nodes are same or not. This method is different from isequalNode(), where two different nodes can be equal but not the same, here the same node means that they are referencing the same object.



Parameters: The “othernode” parameter required in this function.

Return Value: Returns a Boolean value, if matches then True else False.


<!DOCTYPE html>
        HTML | DOM isSameNode() Method
    <!--script to check if nodes are same-->
        function isequal() {
            var out = document.getElementById("result");
            var divele = document.getElementsByTagName("div");
            out.innerHTML += "element 1 equals element 1: " +
                divele[0].isSameNode(divele[0]) + "<br/>";
            out.innerHTML += "element 1 equals element 2: " +
                divele[0].isSameNode(divele[1]) + "<br/>";
            out.innerHTML += "element 1 equals element 3: " +
                divele[0].isSameNode(divele[2]) + "<br/>";
    <h3>Comparing the div elements.</h3>
    <!-- 3 div elements-->
    <button onclick="isequal()">Check</button>
    <!-- Result-->
    <p id="result"></p>

Before clicking on the Check button:

After clicking on the Check button:

Supported Browsers: The browser supported by DOM isSameNode() Method are listed below:

  • Google Chrome
  • Internet Explorer
  • Opera
  • Safari

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :