Element isSameNode Method - Javascript DOM

Javascript examples for DOM:Element isSameNode

Description

The isSameNode() method returns true if the two nodes are the same node, otherwise false.

Parameter Values

Parameter TypeDescription
node Node object Required. The node you want to compare the specified node with

Return Value:

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials