document.adoptNode

  • Revision slug: Web/API/document.adoptNode
  • Revision title: document.adoptNode
  • Revision id: 476205
  • Created:
  • Creator: kscarfone
  • Is current revision? Yes
  • Comment Updated tags

Revision Content

{{DomRef}}

Summary

Adopts a node from an external document. The node and its subtree is removed from the document it's in (if any), and its ownerDocument is changed to the current document. The node can then be inserted into the current document.

Supported since Gecko 1.9 (Firefox 3)

Syntax

node = document.adoptNode(externalNode);
  • node is the adopted node that can be used in the current document. The new node's parentNode is null, since it has not yet been inserted into the document tree.
  • externalNode is the node from another document to be adopted.

Example

{{todo}}

Notes

In general the adoptNode call may fail due to the source node coming from a different implementation, however this should not be a problem with browser implementations.

{{WRONG_DOCUMENT_ERR_note}}

Specification

See also

Revision Source

<div>
  {{DomRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Adopts a node from an external document. The node and its subtree is removed from the document it's in (if any), and its <code><a href="/en-US/docs/DOM/Node.ownerDocument" title="DOM/Node.ownerDocument">ownerDocument</a></code> is changed to the current document. The node can then be inserted into the current document.</p>
<p><strong>Supported since Gecko 1.9 (Firefox 3)</strong></p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<var>node</var> = <em>document</em>.adoptNode(<var>externalNode</var>);
</pre>
<ul>
  <li><code>node</code> is the adopted node that can be used in the current document. The new node's <a href="/en-US/docs/DOM/Node.parentNode"><code>parentNode</code></a> is <code>null</code>, since it has not yet been inserted into the document tree.</li>
  <li><code>externalNode</code> is the node from another document to be adopted.</li>
</ul>
<h2 id="Example" name="Example">Example</h2>
<p>{{todo}}</p>
<h2 id="Notes" name="Notes">Notes</h2>
<p>In general the <code>adoptNode</code> call may fail due to the source node coming from a different implementation, however this should not be a problem with browser implementations.</p>
<p>{{WRONG_DOCUMENT_ERR_note}}</p>
<h2 id="Specification" name="Specification">Specification</h2>
<ul>
  <li><a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-adoptNode">DOM Level 3 Core: Document.adoptNode</a></li>
</ul>
<h2 id="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/DOM/document.importNode">document.importNode</a></li>
</ul>
Revert to this revision