You are here: Reference > JavaScript > client-side > HTML DOM > methods > isEqualNode

isEqualNode method

Browser support:
9
Returns whether the current node is equal to the specified one.
When we speak about nodes in JavaScript, it exactly means node object references. Two node references are the same if they reference to the same object. You can get whether two nodes are the same with the isSameNode method. When two node references are the same then they are also equal, but different node references can also be equal.
Two nodes are equal, when their names are the same, their attributes have the same name and value (the order of attributes may be different), and their child nodes are equal an they are in the same order. That is an simplified definition of two nodes equality, if you need the exact definition of it, please see the isEqualNode (W3C) page.

Syntax:

object.isEqualNode (nodeToCheck);
You can find the related objects in the Supported by objects section below.

Parameters:

nodeToCheck
Required. Reference to the node to compare.

Return value:

Boolean. One of the following values:
false The specified node and the current node are not equal.
true The specified node and the current node are equal.

Example HTML code 1:

This example illustrates the use of the isEqualNode method:
<head>
    <script type="text/javascript">
        var lastButton = null;
        function Test (button) {
            if (lastButton) {
                if (button.isSameNode) {
                    if (button.isSameNode (lastButton)) {
                        alert ("Last time you clicked on the same button.");
                    }
                    else {
                        alert ("You clicked on another button before.");
                    }
                }
                else {
                    alert ("Your browser does not support the isSameNode method.");
                }

                if (button.isEqualNode) {
                    if (button.isEqualNode (lastButton)) {
                        alert ("The two last buttons you last time clicked on is equal.");
                    }
                    else {
                        alert ("The two last buttons you last time clicked on is not equal.");
                    }
                }
                else {
                    alert ("Your browser does not support the isEqualNode method.");
                }
            }
            lastButton = button;
        }
    </script>
</head>
<body>
    Click on the buttons!
    <button onclick="Test (this);">button1</button>
    <button onclick="Test (this);">button1</button>
    <button onclick="Test (this);">button2</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content