JavaScript Document adoptNode() Method

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

What You’ll Learn

document.adoptNode() is an instance method that moves a node from another document into the current one. Learn how ownerDocument changes, why parentNode is null until you insert, MDN’s iframe example, and how adoptNode differs from importNode and cloneNode.

01

Kind

Instance method

02

Arg

externalNode

03

Returns

same node

04

Effect

Moves node

05

vs import

move vs copy

06

Status

Baseline

Introduction

Every DOM node belongs to a Document through ownerDocument. When you build nodes in an iframe, a detached Document, or parsed HTML, those nodes live in a different document than your main page.

MDN: Document.adoptNode(externalNode) transfers a node from another document into the method’s document. The adopted node and its subtree are removed from their original document, and ownerDocument changes to the current document. You can then insert it with appendChild().

💡
Adopt or import first (MDN)

Before inserting nodes from external documents, MDN says you should either clone with document.importNode() or adopt with document.adoptNode(). Appending a foreign node without either can fail or behave inconsistently.

Related tutorials: ownerDocument, cloneNode(), appendChild(), Document constructor.

Understanding document.adoptNode()

An instance method on the live page’s document object.

  • ParameterexternalNode: a node from another document (MDN).
  • Returns — the adopted node (same object as externalNode after the call) (MDN).
  • Removes from source — node and subtree leave the original document (MDN).
  • Updates ownerownerDocument becomes the current document (MDN).
  • parentNode is null — until you insert into the tree (MDN).
  • AlternativeimportNode() copies without removing from source (MDN).

📝 Syntax

JavaScript
document.adoptNode(externalNode)

Parameters

  • externalNode — the node from another document to adopt (MDN).

Return value

The adopted node in the scope of the importing document (MDN).

Common pattern

JavaScript
const otherDoc = new Document();
const p = otherDoc.createElement("p");
p.textContent = "From another document";

const adopted = document.adoptNode(p);
// adopted === p (same object)
// adopted.ownerDocument === document
// adopted.parentNode === null

document.getElementById("host").appendChild(adopted);

⚡ Quick Reference

GoalCode / note
Adopt foreign nodedocument.adoptNode(externalNode)
Insert after adopthost.appendChild(adopted)
Check ownernode.ownerDocument === document
Before insertnode.parentNode === null (MDN)
Copy insteaddocument.importNode(node, true)
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about document.adoptNode().

Call
document.adoptNode

Instance

Returns
same node

MDN

Moves
yes

From source

Status
baseline

Jul 2015

📋 adoptNode() vs importNode()

document.adoptNode(node)document.importNode(node, deep)
Source documentNode removedNode stays
Return valueSame object referenceNew clone
SubtreeEntire subtree movesDeep copy if deep: true
Best whenYou want to move, not copyYou need both copies

Examples Gallery

Examples follow MDN Document: adoptNode(). Adopt first, then insert with appendChild.

📚 Getting Started

Adopt a node from a detached Document and insert it.

Example 1 — Adopt from a detached Document

Create a node in new Document(), adopt it, then append.

JavaScript
const otherDoc = new Document();
const p = otherDoc.createElement("p");
p.textContent = "Adopted paragraph";

const adopted = document.adoptNode(p);
document.getElementById("host").appendChild(adopted);

console.log(adopted.textContent); // "Adopted paragraph"
Try It Yourself

How It Works

MDN: after adoption, adopted === p and ownerDocument is the page document.

Example 2 — MDN: adopt images from an iframe

Move every <img> from an iframe document into the main page.

JavaScript
const iframe = document.querySelector("iframe");
const iframeImages = iframe.contentDocument.querySelectorAll("img");
const newParent = document.getElementById("images");

iframeImages.forEach((imgEl) => {
  newParent.appendChild(document.adoptNode(imgEl));
});
Try It Yourself

How It Works

MDN’s official example: each image is adopted then appended, so they leave the iframe document.

📈 Ownership & Comparison

Inspect ownerDocument, parentNode, and compare with importNode.

Example 3 — ownerDocument changes

Verify the node now belongs to the main document.

JavaScript
const otherDoc = new Document();
const span = otherDoc.createElement("span");
span.textContent = "Hi";

console.log(span.ownerDocument === otherDoc); // true

const adopted = document.adoptNode(span);
console.log(adopted.ownerDocument === document); // true
Try It Yourself

How It Works

See the ownerDocument tutorial for more on document ownership.

Example 4 — parentNode is null until insert

MDN: adopted nodes are detached until you append them.

JavaScript
const otherDoc = new Document();
const div = otherDoc.createElement("div");

const adopted = document.adoptNode(div);
console.log(adopted.parentNode); // null (MDN)

const host = document.getElementById("host");
host.appendChild(adopted);
console.log(adopted.parentNode === host); // true
Try It Yourself

How It Works

Adoption changes ownership only—insertion is a separate step.

Example 5 — adoptNode vs importNode

Adopt moves the original; import leaves a copy behind.

JavaScript
const otherDoc = new Document();
const li = otherDoc.createElement("li");
li.textContent = "Item";
otherDoc.body.appendChild(li);

const adopted = document.adoptNode(li);

console.log({
  adoptedSameRef: adopted === li,
  stillInOtherDoc: otherDoc.body.contains(li) // false — moved
});
Try It Yourself

How It Works

Use importNode when the source document must keep its node. Use adoptNode when you want to move it.

🚀 Common Use Cases

  • Iframe content — move nodes from iframe.contentDocument (MDN example).
  • Parsed Documents — adopt nodes from parseHTML() / DOMParser output.
  • Detached Documents — move nodes built with new Document().
  • Widget reparenting — transfer a subtree without cloning event listeners on a new object.
  • Not for same-document moves — use appendChild directly when ownerDocument already matches.
  • When you need a copy — prefer importNode or cloneNode.

🧠 How adoptNode() Moves a Node

1

Node in foreign document

externalNode.ownerDocument is not the current page (MDN).

Source
2

Call adoptNode

document.adoptNode(externalNode) transfers ownership (MDN).

Adopt
3

Removed from source

Subtree leaves original document; parentNode is null (MDN).

Detach
4

Insert into tree

appendChild(adopted) attaches the node to the live page.

📝 Notes

  • MDN: Baseline Widely available since July 2015.
  • Not Deprecated, Experimental, or Non-standard.
  • Return value and externalNode are the same object after adoption (MDN).
  • Adopt or importNode before inserting foreign nodes (MDN Notes).
  • For same-document reparenting, appendChild alone is enough.
  • Related: ownerDocument, appendChild(), cloneNode(), parseHTML().

Browser Support

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

Baseline Widely available

Document.adoptNode()

Move nodes between documents — change ownerDocument, then append.

Baseline Widely available
Google Chrome Supported
Yes
Microsoft Edge Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Opera Supported
Yes
Internet Explorer 9+
Yes
adoptNode() Baseline

Bottom line: Use document.adoptNode() to move foreign nodes into the current document. Prefer importNode when you need a copy instead of a move.

Conclusion

document.adoptNode() moves a node from another document into the current one. MDN: the node is removed from its source, ownerDocument updates, and parentNode stays null until you insert it.

Continue with append(), ownerDocument, appendChild(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Adopt or import foreign nodes before inserting (MDN)
  • Call appendChild after adoption to attach the node
  • Use importNode when the source must keep its node
  • Check ownerDocument when debugging cross-document bugs
  • Reuse the returned reference—it is the same object (MDN)

❌ Don’t

  • Append foreign nodes without adopt/import (MDN)
  • Assume adoption also inserts into the tree
  • Use adoptNode when you only need a copy—use importNode
  • Forget iframe same-origin rules for contentDocument
  • Confuse adopt with appendChild same-document moves

Key Takeaways

Knowledge Unlocked

Five things to remember about adoptNode()

Move foreign nodes — adopt, then append.

5
Core concepts
🗂02

Moves

node

MDN
🔗03

Same ref

returned

MDN
04

parent

null first

Insert
🛡05

Status

baseline

2015

❓ Frequently Asked Questions

It transfers a node from another document into the current document. The node and its subtree are removed from the original document (if any), and ownerDocument changes to the current document (MDN).
No. MDN marks Document.adoptNode() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
The adopted node in the scope of the importing document. After the call, the return value and the original externalNode reference are the same object (MDN).
MDN: the adopted node's parentNode is null because it has not yet been inserted into the document tree. Call appendChild or similar to attach it.
adoptNode moves the original node (removes it from the source document). importNode clones the node into the current document and leaves the source unchanged.
Use importNode when you need a copy in the current document while keeping the node in the source document, or when cloning parsed HTML from a detached Document (MDN notes).
Did you know?

MDN notes that after document.adoptNode(externalNode), the returned node and externalNode are the same object—but parentNode is still null until you call appendChild or another insertion method.

Next: append()

Learn how Document.append() inserts nodes and strings at the document level.

append() →

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.

6 people found this page helpful