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
Situation
Typical value
In the page / connected shadow
true
Just created / removed / in a fragment only
false
Attr node
Always false
Approach
How to Use isConnected
Read the flag before you assume a node is still in the document.
Hold a node reference (element, text, etc.).
Read node.isConnected.
If true, the node is in a document tree (or connected shadow).
If false, insert it first — or skip DOM work that needs a live node.
Append into a fragment. Fragment is not a Document.
isConnected is false. Still off-document.
Append the fragment to body. Children move into the document.
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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
isConnectedExcellent
Bottom line: Safe everyday DOM API. Use it to guard work that needs a live document node. See the MDN isConnected reference.
Analysis
Performance Notes
Approach
Cost
Best for
isConnected
O(1)
Document-connection check
document.contains(node)
O(1)–O(depth)
Same idea for most elements
parentNode !== null
O(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.
Remember
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).