HTML DOM Document adoptNode()

Example

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

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

Description

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

Note

The adopted node can be of all types.

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

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

See Also:

The Document importNode() Method

The Element cloneNode() Method


Syntax

document.adoptNode(node)

Parameters

Parameter Description
node  Required.
A node from another document.
Can be of any node type.

Return Value

Type Description
NodeThe adopted node.

Browser Support

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

It is fully supported in all modern browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.