Element isSameNode Method - Using the === operator to check if two nodes are the same node: - Javascript DOM

Javascript examples for DOM:Element isSameNode

Description

Element isSameNode Method - Using the === operator to check if two nodes are 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  ww  w.j a  v a2s .  c  om*/
    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