Example 1 — Adopt a Node and Append It
Create a paragraph in another document, adopt it, then append it to the page.
const other = document.implementation.createHTMLDocument("demo");
const p = other.createElement("p");
p.textContent = "Adopted paragraph";
const adopted = document.adoptNode(p);
document.body.appendChild(adopted);
console.log(adopted.textContent);
// "Adopted paragraph"
console.log(adopted.ownerDocument === document);
// true How It Works
- Make another document.
createHTMLDocumentgives a separate HTML document. - Create the node there. The paragraph’s
ownerDocumentisother. - Adopt into this page.
document.adoptNode(p)moves ownership todocument. - Append.
appendChildputs the node in the tree so it appears on the page.

