HTML DOM Document adoptNode() method

Definition and usage

adoptNode() The method adopts a node from another document.

Description

The adopted node can be of any type.

Any child nodes (descendants) of the adopted node are also adopted.

The original node (with child nodes) will be removed from the other document.

See also:

Document importNode() method

Element cloneNode() method

Example

Adopt the first <h1> element that appears in the iframe (another document):

const frame = document.getElementById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.adoptNode(h1);

Try it yourself

Syntax

document.adoptNode(node)

Parameter

Parameter Description
node Required. A node from another document. It can be any node type.

Return value

Type Description
Node Adopted node.

Browser support

document.adoptNode It is a DOM Level 3 (2004) feature.

All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support