Javascript Reference
Categories: document

javascript document importNode( )

@May 11, 2009, 3:11 p.m.
importNode( ) Firefox/Netscape/NN 6 IE n/a Chrome/Safari/DOM 2

importNode(nodeReference, deepBoolean)

 

Imports a node object from another loaded document into the current document, but not yet into the document tree. In many ways, importNode( ) works like cloneNode( ), but it assumes that the source node may exist in an entirely different document tree context (especially in an XML document). W3C DOM rules for this method govern what properties and attributes of the source node make the journey and what happens to them upon their arrival. For example, an Attr node loses its ownerElement (i.e., its value becomes null) when imported from an element in one document into a fragment-like state in the new documentuntil the attribute gets added to an element in the new document. Nodes of Document and DocumentType types are not importable.

 

The importNode( ) method does not assume the responsibility of persistence between documents. That's where, for instance, a JavaScript variable comes into play. As with cloneNode( ), the importNode( ) method does not disturb the source node.

 
Parameters
 
nodeReference

Reference to a node in a different loaded document (including a nonrendered document loaded into the browser by way of the document.implementation.createDocument( ) method).

deepBoolean

Boolean value that controls whether the copy includes all nested nodes (true) or only the current node (false). Required, but applicable primarily to element nodes.

 
Returned Value

Reference to the imported copy of the node object.

Under moderation.
ascendg36ygq - 2016-05-11
Under moderation.
ascend6xdovl - 2016-05-01
this is the proper solution for the javascript error "WRONG_DOCUMENT_ERR: A Node Is Used In A Different Document Than The One That Created It". Just nest it into your call to cloneNode() or replaceChild() like this:

containernode.replaceChild(document.importNode(node_from_other_doc,true),previousnode);
dlatikay - 2011-10-06

Powered by Linode.