Javascript examples for DOM:Element isSameNode
The isSameNode() method returns true if the two nodes are the same node, otherwise false.
Parameter | Type | Description |
---|---|---|
node | Node object | Required. The node you want to compare the specified node with |
A Boolean, returns true if the two nodes are the same node, otherwise false
The following code shows how to Check if two nodes are, in fact, the same node:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <ul id="myList"><li>Coffee</li><li>Tea</li></ul> <script> function myFunction() {//from www .j a va 2 s . com var item1 = document.getElementById("myList"); var item2 = document.getElementsByTagName("UL")[0]; if (item1 === item2) { console.log("They Are The Same!"); } else { console.log("They are not the same."); } } </script> </body> </html>