How to use DOM Node isEqualNode in JavaScript

In this article I am going to explain about DOM Node isEqualNode() Method in JavaScript
  • 2050

JavaScript DOM Node isEqualNode() Method

JavaScript isEqualNode() method use for check two node is equal or not. If node are equal then it will return true othaer wise false. Equal node have following condition.

  • Node type must be same.
  • Number of child node must be same.
  • They have same attribute.
  • They have same name, same value, same namespace.

Syntax

node.isEqualNode(node)

Example

<html>

<head>

    <script type="text/javascript">

        function myfun(x, y) {

            var item1 = document.getElementById(x).firstChild;

            var item2 = document.getElementById(y).firstChild;

            var x = document.getElementById("tst");

            x.innerHTML = item1.isEqualNode(item2);

        }

    </script>

</head>

<body>

    <h1 id="tst">

    </h1>

    First List:

    <ul id="l1">

        <li>welcome</li><li>ABC</li></ul>

    Second List:

    <ul id="l2">

        <li>welcome</li><li>ABC</li></ul>

    <p>

        cleck button to check list item</p>

    <button onclick="myfun('l1','l2')">

        check</button>

</body>

</html>

 

Output

 

Before click

 

 isEqual1.jpg

 

After click

 

 isEqual2.jpg

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.