The Node.isConnected property returns a Boolean: whether the node is connected to a Document (directly or indirectly). Learn create-vs-append, Shadow DOM, why Attr is always false, and five examples with try-it labs.
01
Kind
Read-only property
02
Returns
boolean
03
Means
In a Document?
04
Shadow
Counts when linked
05
Attr
Always false
06
Status
Baseline widely
Fundamentals
Introduction
Creating a node with document.createElement() does not put it on the page. Until you insert it (or it lives under a connected shadow root), isConnected is false. After a successful insert into the document tree, it becomes true.
That Boolean is useful in components, custom elements, and cleanup logic: “Am I still in the document?”
💡
Beginner tip
Prefer node.isConnected over guessing with document.contains(node) when you only need a yes/no connected check—it also covers Shadow DOM connection correctly.
Concept
Understanding isConnected
MDN: the read-only isConnected property returns a boolean indicating whether the node is connected (directly or indirectly) to a Document object.
true — the node’s root is a document (including via shadow trees that are connected).
false — detached node, fragment-only node, or special cases like Attr.
Read-only — you cannot assign node.isConnected = true.
Changes when you append, remove, or adopt nodes.
Foundation
📝 Syntax
JavaScript
const connected = node.isConnected; // true or false
Return value
A boolean: true if connected to its relevant context object (a document), otherwise false.
Special Case
⚠️ Attr Is Never Connected
An Attr node always returns false for isConnected, even when its ownerElement is in the document. Attributes are associated with elements but are not part of the node tree the same way—an Attr has no parent and is its own root, so it is never considered connected.
Cheat Sheet
⚡ Quick Reference
Situation
Typical isConnected
document.createElement("p")
false
After document.body.appendChild(el)
true
After el.remove() / removeChild
false
Node inside connected shadow root
true
Attr node
Always false
Child only inside a DocumentFragment
false until inserted into a document
MDN status
Baseline Widely available (since January 2020)
Snapshot
🔍 At a Glance
Four facts to remember about Node.isConnected.
Returns
boolean
true / false
Baseline
widely
Since Jan 2020
Access
read-only
No assignment
Means
in Document?
Direct or via shadow
Hands-On
Examples Gallery
Examples follow MDN Node.isConnected patterns. Use View Output or Try It Yourself for each case.
📚 Getting Started
Create a node, insert it, then detach it again.
Example 1 — Standard DOM Create & Append
MDN-style: disconnected after create, connected after append.
Appending a fragment inserts its children into the target. Those children become connected; the empty fragment itself is not what you keep using afterward.
Applications
🚀 Common Use Cases
Custom elements — run setup when connected; tear down when not.
Avoid double-insert — skip appendChild if already connected.
Cleanup guards — do not update DOM if !node.isConnected.
Shadow components — confirm styles/slots are in a connected tree.
Debugging detach bugs — log isConnected after remove/replace.
🧠 How isConnected Works
1
Find the node’s root
Walk up parents / shadow hosts to the tree root.
Root
2
Is the root a Document?
Connected trees end at a document (including via shadow).
Check
3
Apply special cases
Attr nodes always report false.
Exceptions
4
✓
Return the Boolean
Your script branches on true or false.
Important
📝 Notes
Baseline Widely available (MDN, since January 2020).
Not Deprecated, Experimental, or Non-standard — no status banner required.
Read-only Boolean; insertion/removal updates the value.
Node.isConnected is Baseline Widely available across modern browsers (MDN: since January 2020). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Node.isConnected
Safe for modern production apps. Use it to detect whether a node is still in a Document (including connected Shadow DOM).
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNot supported in IE 11 · use a polyfill if needed
Unavailable
isConnectedExcellent
Bottom line: Check isConnected before DOM updates or cleanup. Remember Attr nodes always return false.
Wrap Up
Conclusion
Node.isConnected answers one question: is this node tied to a document right now? Use it after create/append/remove, inside shadow trees, and remember that Attr nodes always report false.
Treat Shadow DOM children as connected when the host is
Re-check after async work (node may have been removed)
Use it in custom element connect/disconnect logic
Remember Attr is a special always-false case
❌ Don’t
Assign to isConnected (read-only)
Assume createElement nodes are already on the page
Expect attribute nodes to report true
Forget fragment children start disconnected
Confuse DOM Node with the Node.js runtime
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about isConnected
Boolean link to a Document.
5
Core concepts
🔗01
Boolean
in Document?
API
📤02
Create false
append true
DOM
🎨03
Shadow OK
when host linked
Shadow
🔖04
Attr
always false
Exception
📁05
Fragments
until inserted
Pattern
❓ Frequently Asked Questions
It is a read-only Boolean. true means the node is connected (directly or indirectly) to a Document. false means it is not in a document tree yet (or was removed).
No. MDN marks Node.isConnected as Baseline Widely available (since January 2020). It is a standard DOM property — 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 node tree the same way elements are. 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).
Did you know?
Custom Elements expose connectedCallback and disconnectedCallback around the same idea. Reading this.isConnected inside those callbacks (or later async work) tells you whether the element is still in the document.