Open In App
Related Articles

HTML DOM isSameNode() Method

Improve Article
Save Article
Like Article

The isSameNode() method checks whether the two nodes are the 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 is required in this function. 

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

Example: In this example, we will use isSameNode() method


<!DOCTYPE html>
        HTML | DOM isSameNode() Method
    <!--script to check if nodes are same-->
        function isequal() {
            let out = document.getElementById("result");
            let 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>



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

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 9
  • Opera 12.1
  • Safari 3
  • Firefox 48

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

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