JavaScript document.importNode() Method

You are Here:

JavaScript document.importNode() Method

The document.importNode() method imports a node from another document to be inserted into the current document later.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <iframe src="/js/document-adoptnode/iframe"></iframe> <button onclick="myFunction()">Click Me</button> <script> var frame = document.getElementsByTagName("IFRAME")[0] function myFunction() { var h = frame.contentWindow.document.getElementsByTagName("h1")[0]; var x = document.importNode(h, true); document.body.appendChild(x); } </script> </body> </html>

Syntax

document.importNode(externalNode, deep)

Parameter Values

ValueTypeExplanation
externalNodeRequiredThe external Node to import into the current document.
deepRequiredIf deep is set to true, then externalNode and all of its descendants are copied.
If deep is set to false, then only externalNode is imported — the new node has no children.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author