The isEqualNode()
method checks if two nodes are equal.
isEqualNode |
Yes | 9.0 | Yes | Yes | Yes |
node.isEqualNode(node)
Parameter | Type | Description |
---|---|---|
node | Node object | Required. The node to compare |
It returns a Boolean type.
true
if the two nodes are equal, otherwise false
.
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: