JavaScript Node isEqualNode() Method

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

What Is isEqualNode()?

node.isEqualNode(otherNode) returns true when two nodes are structurally equal — same type and matching defining data (for elements: attributes, children, and so on) (MDN).

Status: Baseline Widely available (since July 2015) — not Deprecated, Experimental, or Non-standard. For object identity, use === (MDN: prefer that over isSameNode()).

Remember
a.isEqualNode(b)
→ true if a and b look the same (type, attrs, subtree…)
→ false if different — or if b is null

a === b              → same object?
a.isEqualNode(b)     → equal structure?

cloneNode(true):
  equal? often true
  same object? false
GoalPrefer
Same structure / contenta.isEqualNode(b)
Same object in memorya === b
Copy then comparecloneNode() + isEqualNode

How to Use isEqualNode()

Pass another node (or null) and read the boolean.

  1. Get two nodes to compare.
  2. Call a.isEqualNode(b).
  3. Treat null as always unequal (MDN).
  4. Use === when you need identity, not just equality.
PieceRequired?Role
nodeYesNode calling the method
otherNodeYes (may be null)Node to compare against
Return—true or false

Pseudocode

Pseudocode
if otherNode is null:
    return false

if a and b have same type
   and matching defining data
   and matching children:
    return true
else:
    return false

// identity is separate:
a === b

Cheat Sheet

Keep these equality facts handy.

TopicDetail
Syntaxnode.isEqualNode(otherNode)
Returnsboolean
ComparesType + defining characteristics + subtree
nullAlways false (MDN)
vs ===Structure vs same object
vs isSameNodeLegacy identity alias — prefer ===
StandardBaseline Widely available (since July 2015)

Live Preview

Compare three divs (MDN-style): matching content, different content, and self.

Nodes

Browser demo of Node.isEqualNode() — structure, not identity.

Result
Choose a pair, then Compare…

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Equal Content, Different Nodes

Two separate elements with the same markup can be equal (MDN).

JavaScript
const divs = document.querySelectorAll("#box div");

console.log(divs[0].isEqualNode(divs[0])); // true
console.log(divs[0].isEqualNode(divs[1])); // false (different text)
console.log(divs[0].isEqualNode(divs[2])); // true  (same content)
Try It Yourself

How It Works

  1. Same node. A node is always equal to itself.
  2. Different text. Defining content differs → false.
  3. Matching twin. Same type and content → true.
  4. Still two objects. Equality is not identity.

Example 2 — Equal Clone, Not the Same Object

A deep clone can pass isEqualNode but fail ===.

JavaScript
const original = document.getElementById("card");
const copy = original.cloneNode(true);

console.log(original.isEqualNode(copy)); // true
console.log(original === copy);          // false
console.log(original.isSameNode(copy));  // false (legacy; prefer ===)
Try It Yourself

How It Works

  1. Clone deeply. cloneNode(true) copies the subtree.
  2. Structure matches. isEqualNode → true.
  3. Different objects. === → false.
  4. Pick the right test. Equality for “looks the same,” identity for “this node.”

Example 3 — null Is Never Equal

MDN: if otherNode is null, the result is always false.

JavaScript
const el = document.createElement("div");
el.textContent = "hi";

console.log(el.isEqualNode(null)); // false
console.log(el.isEqualNode(el));   // true
Try It Yourself

How It Works

  1. Pass null. Allowed, but never equal (MDN).
  2. Guard missing nodes. Useful when a lookup may return null.
  3. Self still works. Comparing a node to itself is true.
  4. Argument required. Always pass a Node or null explicitly.

Edge Cases & Pitfalls

Check these before treating isEqualNode like ===.

identity

Equal ≠ same object

Matching twins and clones can be equal while === stays false. Prefer === for identity (MDN for isSameNode).

null

null always returns false

MDN: isEqualNode(null) is never true.

attrs

Attributes and children count

Different id, class, or child lists usually make nodes unequal — type alone is not enough.

clone

Shallow clone may not match

cloneNode(false) skips children, so deep trees often fail equality vs the original.

Browser Support

Node.isEqualNode() is marked Baseline Widely available on MDN (since July 2015).

✓ Baseline · Widely available

Node.isEqualNode()

Compares two nodes for structural equality (type and defining characteristics). Returns false for null. Not the same as object identity (===).

100% Widely available
Google Chrome Yes (Baseline)
Yes
Microsoft Edge Yes (Baseline)
Yes
Mozilla Firefox Yes (Baseline)
Yes
Apple Safari Yes (Baseline)
Yes
Opera Yes (Baseline)
Yes
Internet Explorer Supported (legacy)
Yes
isEqualNode() Excellent

Bottom line: Safe everyday DOM API. Use === for identity. See the MDN isEqualNode reference.

Performance Notes

ApproachCostBest for
=== / identityO(1)“Is this the same node?”
isEqualNode small treesCheapTypical UI nodes
isEqualNode huge subtreesWalks the treeAvoid in hot loops on large DOM

Equality can walk attributes and descendants. Prefer === when you only need identity, and keep deep compares off animation / scroll paths.

Key Takeaways

  • Structural equality: type and defining data must match.
  • Not identity: use === for the same object.
  • null → false: never equal to a real node.
  • Clones: deep clones are often equal, never the same object.

One line: isEqualNode asks “do these nodes look the same?” — not “are they the same object?”

Frequently Asked Questions

It returns true if two nodes are equal in type and defining characteristics (for elements: id, attributes, children, and so on). The exact checklist depends on the node types.
No. MDN marks Node.isEqualNode() as Baseline Widely available (since July 2015). It is a standard DOM method — not Deprecated, Experimental, or Non-standard.
=== (and isSameNode) ask “is this the exact same object?” isEqualNode asks “do these two nodes look the same structurally?” A deep clone can be equal but not the same object.
isEqualNode(null) always returns false. The argument is required in the signature but may be set to null.
Yes. If they have the same type, matching attributes, and matching content structure, isEqualNode can return true even though they are separate nodes.
Equality is about matching attributes and values as defined by the DOM, not about how you wrote the HTML. Focus on type, attributes, and subtree content.

Next: isSameNode()

Learn the legacy same-object check — and why === is preferred.

isSameNode tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful