JavaScript Node isConnected Property

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

What Is isConnected?

The read-only isConnected property returns a boolean: true if the node is connected (directly or indirectly) to a Document, otherwise false (MDN).

Status: Baseline Widely available (since January 2020) — not Deprecated, Experimental, or Non-standard. Note: an Attr node always returns false, even when its ownerElement is connected.

Remember
node.isConnected
→ true   // in a Document (or connected shadow tree)
→ false  // created but not inserted, or removed

MDN flow:
  el = document.createElement("p")  → false
  document.body.appendChild(el)     → true
SituationTypical value
In the page / connected shadowtrue
Just created / removed / in a fragment onlyfalse
Attr nodeAlways false

How to Use isConnected

Read the flag before you assume a node is still in the document.

  1. Hold a node reference (element, text, etc.).
  2. Read node.isConnected.
  3. If true, the node is in a document tree (or connected shadow).
  4. If false, insert it first — or skip DOM work that needs a live node.
PieceRequired?Role
nodeYesAny Node to check
Return—boolean
Writable?NoRead-only

Pseudocode

Pseudocode
el = document.createElement("p")
print el.isConnected          // false

document.body.appendChild(el)
print el.isConnected          // true

el.remove()
print el.isConnected          // false

// Attr caveat (MDN):
attr.isConnected              // always false

Cheat Sheet

Quick facts for connected vs detached nodes.

TopicDetail
Returnstrue / false
MeaningConnected to a Document?
After createfalse until inserted
Shadow DOMtrue if host is connected
AttrAlways false
StandardBaseline Widely available (since Jan 2020)

Live Preview

Create a node, append it, then remove it — watch isConnected flip.

Actions

Browser demo of Node.isConnected through create → append → remove.

Result
Click Create to start…

JavaScript Examples

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

Example 1 — Create then Append

MDN standard DOM: false after create, true after append.

JavaScript
const test = document.createElement("p");
console.log(test.isConnected); // false

document.body.appendChild(test);
console.log(test.isConnected); // true
Try It Yourself

How It Works

  1. createElement. Builds a node outside the document.
  2. isConnected is false. No Document root yet.
  3. appendChild to body. Inserts it into the live tree.
  4. isConnected is true. Connected (directly or indirectly) to the Document.

Example 2 — Remove → false Again

Detaching a node flips the flag back to false.

JavaScript
const el = document.createElement("div");
document.body.appendChild(el);
console.log(el.isConnected); // true

el.remove();
console.log(el.isConnected); // false
Try It Yourself

How It Works

  1. Append the element. It becomes connected.
  2. Call remove(). Detaches it from its parent.
  3. isConnected becomes false. No longer under a Document.
  4. Reference still works. You can append it again later.

Example 3 — Shadow DOM

MDN: a node in a connected shadow root reports true.

JavaScript
const host = document.createElement("div");
document.body.appendChild(host);
const shadow = host.attachShadow({ mode: "open" });
const style = document.createElement("style");

console.log(style.isConnected); // false
shadow.appendChild(style);
console.log(style.isConnected); // true
Try It Yourself

How It Works

  1. Host is in the document. Shadow tree can connect through it.
  2. Create style outside. Starts disconnected.
  3. Append into shadow. Indirectly linked to the Document.
  4. isConnected is true. Shadow counts as connected context.

Example 4 — Attr Always false

MDN note: attribute nodes never report connected, even on a live element.

JavaScript
const el = document.createElement("a");
el.setAttribute("href", "/docs");
document.body.appendChild(el);

const attr = el.getAttributeNode("href");
console.log(el.isConnected);   // true
console.log(attr.isConnected); // false
Try It Yourself

How It Works

  1. Element is connected. el.isConnected is true.
  2. Get the Attr node. Linked via ownerElement.
  3. Attr is not in the node tree. No parent; own root.
  4. attr.isConnected stays false. MDN documents this quirk.

Example 5 — DocumentFragment

Children inside a fragment alone are not connected until inserted.

JavaScript
const frag = document.createDocumentFragment();
const item = document.createElement("li");
frag.appendChild(item);
console.log(item.isConnected); // false

document.body.appendChild(frag);
console.log(item.isConnected); // true
Try It Yourself

How It Works

  1. Append into a fragment. Fragment is not a Document.
  2. isConnected is false. Still off-document.
  3. Append the fragment to body. Children move into the document.
  4. isConnected becomes true. Now under the Document tree.

Edge Cases & Pitfalls

Check these before treating isConnected as “has a parent.”

attr

Attr always false

MDN: attribute nodes are never considered connected, even on a live element.

fragment

Fragment-only children

Nodes living only in a DocumentFragment stay false until inserted into a document.

parent

Not the same as parentNode

parentNode can exist on detached trees; isConnected asks specifically about a Document root.

shadow

Connected shadow counts

If the host is in the document, nodes inside its shadow root report true.

Browser Support

Node.isConnected is marked Baseline Widely available on MDN (since January 2020).

✓ Baseline · Widely available

Node.isConnected

Boolean: true if the node is connected to a Document (including connected shadow trees). Attr nodes always return false.

100% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
isConnected Excellent

Bottom line: Safe everyday DOM API. Use it to guard work that needs a live document node. See the MDN isConnected reference.

Performance Notes

ApproachCostBest for
isConnectedO(1)Document-connection check
document.contains(node)O(1)–O(depth)Same idea for most elements
parentNode !== nullO(1)Has a parent — not Document proof

Prefer isConnected when the question is “in a document?” — it is clear, cheap, and matches the DOM definition.

Key Takeaways

  • Boolean flag — connected to a Document or not.
  • Create → false; append → true; remove → false.
  • Shadow DOM: connected host → children report true.
  • Attr caveat: always false (MDN).

One line: isConnected answers “is this node in a Document tree?” — not “does it have a parent?”

Frequently Asked Questions

A read-only boolean: true if the node is connected (directly or indirectly) to a Document, false if it is not in a document tree.
No. MDN marks Node.isConnected as Baseline Widely available (since January 2020). It is not Deprecated, Experimental, or Non-standard.
document.createElement("p") starts with isConnected === false. After you append it into the document (for example document.body.appendChild(el)), isConnected becomes true.
Yes. Nodes appended into a shadow root that is itself connected to a document report isConnected === true.
Attribute nodes are not part of the element node tree. Even when ownerElement is connected, Attr.isConnected is always false because an Attr has no parent and is its own root.
Not while they live only inside the fragment. They become connected after you insert them into a document (appending the fragment moves its children into the tree).

Next: lastChild

Learn how to read the last child node of a parent.

lastChild 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.

8 people found this page helpful