# XML/HTML DOM: isEqualNode() Method
The `isEqualNode()` method is a standard DOM Node method used to determine whether two nodes are equal. It returns `true` if the nodes meet all the criteria for equality, and `false` otherwise.
---
## Definition and Usage
The `isEqualNode()` method checks if two DOM nodes are equal.
It is important to distinguish between **equality** (`isEqualNode()`) and **identity** (`isSameNode()` or the `===` operator):
* **Identity (`===` / `isSameNode`)**: Checks if two references point to the exact same object in memory.
* **Equality (`isEqualNode`)**: Checks if two different node objects have the same type, attributes, and child structure (deep equality).
### Criteria for Node Equality
Two nodes are considered equal if all of the following conditions are met:
1. They have the same node type (`nodeType`).
2. They have the same node name (`nodeName` / `localName`).
3. They have the same namespace URI and prefix (if applicable).
4. Their local attributes are identical (same names, values, and number of attributes, though order does not matter).
5. Their child nodes are equal, including all descendants in the same order (deep comparison).
6. Their text content (for text nodes) or values (for attribute/comment nodes) are identical.
---
## Syntax
```javascript
nodeObject.isEqualNode(node)
```
### Parameters
| Parameter | Type | Required / Optional | Description |
| :--- | :--- | :--- | :--- |
| `node` | `Node` | **Required** | The target node object to compare with the current node. |
### Return Value
* **Type**: `Boolean`
* **Description**: Returns `true` if the nodes are equal; otherwise, returns `false`. If the parameter passed is `null` or not a valid Node, it returns `false`.
---
## Code Examples
### Example 1: Comparing XML Nodes
The following example loads an XML document ("books.xml") and checks whether the second and third `` elements are equal:
```javascript
// Load the XML document
xmlDoc = loadXMLDoc("books.xml");
// Select the second and third elements
let x = xmlDoc.getElementsByTagName("book");
let y = xmlDoc.getElementsByTagName("book");
// Check if they are equal
console.log(x.isEqualNode(y));
// Output: false (assuming they have different content or attributes)
```
### Example 2: Comparing HTML Elements (Deep Equality)
This example demonstrates how `isEqualNode()` behaves with HTML elements, showing that it performs a deep comparison of attributes and child nodes.
```html
Hello World
Hello World
Hello World
```
---
## Key Considerations
* **Whitespace Sensitivity**: `isEqualNode()` is highly sensitive to whitespace. Two elements with the exact same tags and text content may return `false` if one has extra spaces or line breaks inside it, as these are treated as text nodes.
* **Attribute Order**: The order of attributes on an element does not affect equality. For example, `` is equal to ``.
* **Performance**: Because `isEqualNode()` performs a deep, recursive comparison of the entire subtree, it can be computationally expensive on large DOM structures. Use it carefully in performance-critical paths.
---
## Browser Compatibility
The `isEqualNode()` method is part of the W3C DOM Level 3 Core Specification and is fully supported in all modern web browsers:
* Google Chrome (All versions)
* Microsoft Edge (All versions)
* Mozilla Firefox (All versions)
* Apple Safari (All versions)
* Opera (All versions)
* Internet Explorer 9+