DOM:element.cloneNode
From MDC
Contents |
[edit] Summary
Returns a duplicate of the current node.
[edit] Syntax
dupNode = element.cloneNode(deep);
-
deepis a required boolean value indicating whether the clone is a deep clone or not (see notes below).
[edit] Example
p = document.getElementById("para1");
p_prime = p.cloneNode(true);
[edit] Notes
Cloning a node copies all of its attributes and their values.
The duplicate node returned by cloneNode is not part of the document until it is added to another node that is part of the document using appendChild or a similar method. It also has no parent until it is appended to another node.
If deep is set to false, none of the child nodes are cloned. Any text that the node contains is not cloned either, as it is contained in one or more child Text nodes.
If deep evaluates to true, the whole subtree (including text that may be in child Text nodes) is copied too. For empty nodes (e.g. IMG and INPUT elements) it doesn't matter whether deep is set to true or false but you still have to provide a value.
Note that cloneNode may lead to duplicate element-ids in a document!
To clone node for appending to a different document, use importNode instead.