- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM isSameNode( ) Method
The HTML DOM isSameNode() method returns a boolean value (true/false) if two nodes are same or not.
Note − The isSameNode() method is deprecated so you should use ‘===’ operator instead.
Syntax
Following is the syntax −
Calling isSameNode()
nodeOne.isSameNode(NodeTwo)
Example
Let us see an example for isSameNode() method −
<!DOCTYPE html> <html> <head> <title>isSameNode()</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } ul{ width: 30%; margin: 0 auto; } </style> </head> <body> <form> <fieldset> <legend>isSameNode( )</legend> <h3>John Doe's Achievements</h3> <ul> <li id="cricket">Trophy 1</li> <li>Trophy 2</li> <li>Trophy 3</li> </ul> <input type="button" onclick="confirmTrophy()" value="Check"> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var cricketTrophy = document.getElementById("cricket"); var trophyOne = document.getElementsByTagName("li")[0]; divDisplay.textContent = 'NOTE: Check if Trophy 1 was won in cricket'; function confirmTrophy() { if(cricketTrophy.isSameNode(trophyOne)) divDisplay.textContent = 'Trophy 1 was indeed won in cricket'; else divDisplay.textContent = 'Trophy 1 was not won in cricket'; } </script> </body> </html>
Output
This will produce the following output −
Before clicking ‘Check’ button −
After clicking ‘Check’ button −
Advertisements