HTML | DOM isSameNode() Method
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.
Syntax:
node.isSameNode(othernode)
Parameters: The “othernode” parameter required in this function.
Return Value: Returns a Boolean value, if matches then True else False.
Example:
<!DOCTYPE html> <html> <head> <title> HTML | DOM isSameNode() Method </title> <!--script to check if nodes are same--> <script> 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/>"; } </script> </head> <body> <h3>Comparing the div elements.</h3> <!-- 3 div elements--> <div>GeeksforGeeks</div> <div>GfG</div> <div>GeeksforGeeks</div> <button onclick="isequal()">Check</button> <!-- Result--> <p id="result"></p> </body> </html> |
Output:
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
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM setAttributeNode() Method
- HTML | DOM getBoundingClientRect() Method
- HTML | DOM close() Method
- HTML | DOM hasFocus() Method
- HTML | DOM isEqualNode() Method
- HTML | DOM insertAdjacentHTML() Method
- HTML | DOM hasAttributes() Method
- HTML | DOM isDefaultNamespace() Method
- HTML | DOM writeln() Method
- HTML | DOM getElementsByClassName() Method
- HTML | DOM normalizeDocument() Method
- HTML | DOM write() Method
- HTML | DOM getElementsByName() Method
- HTML | DOM getNamedItem() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


