JS isEqualNode

The isEqualNode() returns true if two elements (or nodes) are equal.

Syntax

element.isEqualNode(node)
        or
node.isEqualNode(node)

Parameters

Parameter Description
node Required.
The node to compare.

Return Value

Type Description
Boolean true if the nodes are equal, otherwise false.


html file

<!DOCTYPE html>
<html>
<head>
    <title>DOM Navigation</title>
</head>
<body>
    <ul id="list-1">
        <li class="abc">orange</li>
        <li>Banana</li>
        <li>Apple</li> 
        <li>Grapes</li>
    </ul>
    <ul id="list-2">
        <li>Guava</li>
        <li class="abc">orange</li>
        <li>PineApple</li> 
    </ul>
    <script src="js/dom-create.js"></script>
</body>
</html>

dom-create.js
var target1 = document.getElementById("list-1").firstElementChild;

var target2 = document.getElementById("list-2").children[1];

var equal = target1.isEqualNode(target2);

console.log(equal);