JavaScript Node isEqualNode() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Instance method

What You’ll Learn

The Node.isEqualNode() method tests whether two nodes are equal in type and defining characteristics. Learn how it differs from object identity (===), how clones compare, and what null does.

01

Kind

Instance method

02

Returns

boolean

03

Compares

Structure / data

04

vs ===

Identity vs equal

05

null

Always false

06

Status

Baseline widely

Introduction

Sometimes you need to know if two nodes look the same—same tag, attributes, and content—even if they are not the same object in memory. isEqualNode() is that structural comparison.

By contrast, nodeA === nodeB (or isSameNode) asks whether you hold the exact same node reference. A deep cloneNode(true) is usually equal but not the same.

💡
Beginner tip

Use === for “is this the node I stored?” Use isEqualNode for “would these two trees print the same?”

Understanding isEqualNode()

MDN: two nodes are equal when they have the same type, matching defining characteristics (for elements: id, number of children, and so on), matching attributes, and so forth. The exact checklist depends on the node types.

  • true — nodes match structurally / by definition for their types.
  • false — something differs, or otherNode is null.
  • Self — a node is equal to itself.
  • Separate nodes — can still be equal if contents match.

📝 Syntax

JavaScript
const equal = node.isEqualNode(otherNode);

Parameters

  • otherNode — The node to compare with. Required in the signature, but may be null (then the result is always false).

Return value

A boolean: true if the nodes are equal, otherwise false.

⚖️ isEqualNode() vs === / isSameNode()

isEqualNode()=== / isSameNode()
QuestionSame structure / data?Same object in memory?
Deep cloneUsually truefalse
Same referencetruetrue
Two matching siblingsMay be truefalse
Best forContent comparisonStored node identity

⚡ Quick Reference

GoalCode
Structural equalitya.isEqualNode(b)
Same object?a === b
Clone equal?node.isEqualNode(node.cloneNode(true))
Null argumentnode.isEqualNode(null)false
Self checknode.isEqualNode(node)true
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about Node.isEqualNode().

Returns
boolean

true / false

Baseline
widely

Since July 2015

Means
looks equal

Not identity

null
false

Always

Examples Gallery

Examples follow MDN Node.isEqualNode() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

Matching siblings, self-equality, and null.

Example 1 — Matching and Different Divs (MDN-style)

First and third match; the second differs.

JavaScript
const divList = document.getElementsByTagName("div");

console.log(divList[0].isEqualNode(divList[0])); // true
console.log(divList[0].isEqualNode(divList[1])); // false
console.log(divList[0].isEqualNode(divList[2])); // true
Try It Yourself

How It Works

Div 0 and div 2 share the same content structure, so they are equal even though they are different objects. Div 1 has different text.

Example 2 — A Node Equals Itself

Self-comparison is always equal (and identical).

JavaScript
const el = document.getElementById("box");
console.log(el.isEqualNode(el)); // true
console.log(el === el);          // true
Try It Yourself

How It Works

Both equality and identity succeed for the same reference.

📈 Null, Clones & Attributes

Edge cases and the clone vs identity distinction.

Example 3 — null Always Returns false

Safe when a lookup might miss.

JavaScript
const el = document.getElementById("box");
const missing = document.getElementById("nope"); // null

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

How It Works

MDN: if otherNode is null, isEqualNode() always returns false.

Example 4 — Clone Is Equal, Not Identical

Deep clones usually match with 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
Try It Yourself

How It Works

The clone duplicates structure and attributes. It is a new object, so identity fails while structural equality succeeds.

Example 5 — Different Attributes Are Not Equal

Matching text is not enough if attributes differ.

JavaScript
const a = document.createElement("button");
const b = document.createElement("button");
a.textContent = b.textContent = "Save";
a.id = "save-a";
b.id = "save-b";

console.log(a.isEqualNode(b)); // false

b.id = "save-a";
console.log(a.isEqualNode(b)); // true
Try It Yourself

How It Works

Element equality includes attributes such as id. Align them and the nodes become equal.

🚀 Common Use Cases

  • Checking whether a template clone still matches an expected structure.
  • Detecting duplicate markup patterns in the page.
  • Comparing before/after snapshots of a node tree in tests.
  • Teaching the difference between equality and identity for DOM nodes.
  • Validating that two independently built fragments match.

🔧 How It Works

1

Pass otherNode

null immediately yields false; otherwise compare begins.

Arg
2

Check type & defining data

Node type, attributes, children, and related fields must align.

Match
3

Walk the subtree

Descendants are part of equality for element trees.

Tree
4

Boolean result

true if everything required matches for those node types.

📝 Notes

Universal Browser Support

Node.isEqualNode() is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Node.isEqualNode()

Safe for production. Prefer === for identity; isEqualNode for structural sameness.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium & Legacy
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Long-standing support in legacy IE
Full support
isEqualNode() Excellent

Bottom line: Structural equality of two nodes; null → false; clones can be equal without being identical.

Conclusion

Node.isEqualNode() compares nodes by type and defining characteristics. Remember that equal is not the same as identical, and that null always fails the check.

Continue with isSameNode(), cloneNode(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use isEqualNode for structural comparisons
  • Use === when you need the same object
  • Handle null lookups safely
  • Pair with cloneNode when demonstrating equality vs identity
  • Compare attributes intentionally in tests

❌ Don’t

  • Assume equal nodes are the same reference
  • Confuse with isSameNode / ===
  • Forget that attribute differences break equality
  • Confuse DOM Node with the Node.js runtime
  • Pass invalid types and expect portable results

Key Takeaways

Knowledge Unlocked

Five things to remember about isEqualNode()

Structural equality of two DOM nodes.

5
Core concepts
📜 02

Structure

type + attrs + kids

Meaning
⚖️ 03

Not ===

identity differs

Compare
📋 04

Clones

often equal

cloneNode
05

null → false

safe miss

Edge

❓ 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.
Did you know?

MDN’s classic demo compares three <div>s: the first equals itself, does not equal the middle (different text), and equals the third (same contents)—even though the first and third are separate elements in the document.

Next: isSameNode()

Learn identity checks—legacy alias for ===.

isSameNode() →

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.

5 people found this page helpful