English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM adoptNode() Method

HTML DOM Document Object

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

If all child nodes (descendants) of the adopted node (if any) will also be adopted.

The adopted node and its child nodes will be removed from its original document.

Usingdocument.importNode()method to copy a node from another document without deleting it.

You can also use element.cloneNode()The method copies a node from the current document without deleting it.

Syntax:

document.adoptNode(externalNode)
var iframe = document.querySelector(&#)39;iframe');
var iframeImages = iframe.contentDocument.querySelectorAll('h2');
var newParent = document.getElementById('result');
iframeImages.forEach(function(elem) {
newParent.appendChild(document.adoptNode(elem));
});
Test See‹/›

Browser Compatibility

All browsers fully support the acceptNode() method:

Method
adoptNode()YesYesYesYesYes

Parameter Value

ParameterDescription
externalNodeA node from another document will be adopted

Technical Details

Return Value:Represents the Node object of the adopted node
DOM Version:DOM Level3

HTML DOM Document Object