Javascript Reference - HTML DOM isEqualNode Method








The isEqualNode() method checks if two nodes are equal.

Browser Support

isEqualNode Yes 9.0 Yes Yes Yes

Syntax

node.isEqualNode(node)

Parameters

Parameter Type Description
node Node object Required. The node to compare




Return Value

It returns a Boolean type.

true if the two nodes are equal, otherwise false.

Example

The following code shows how to check if two list items are equal.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction('myList1','myList2')">Compare List 1 and 2</button>
<ul id="myList1"><li>A</li><li>C</li></ul>
<ul id="myList2"><li>B</li><li>D</li></ul>
<script>
function myFunction(x,y)<!-- ww  w .j  av  a2s . co  m-->
{
    var item1=document.getElementById(x).firstChild;
    var item2=document.getElementById(y).firstChild;
    console.log(item1.isEqualNode(item2));
}
</script>

</body>
</html>

The code above is rendered as follows: