Node.cloneNode() method returns a duplicate of the
node on which this method was called.
let newClone = node.cloneNode([deep])
The node to be cloned.
The new node, cloned from
newClonehas no parent and is not part of the document, until it is added to another node that is part of the document (using
Node.appendChild()or a similar method).
nodeand its whole subtree—including text that may be in child
Textnodes—is also copied.
nodewill be cloned. Any text that
nodecontains is not cloned, either (since text is contained by one or more child
let p = document.getElementById("para1") let p_prime = p.cloneNode(true)
Cloning a node copies all of its attributes and their values,
including intrinsic (inline) listeners. It does not copy event listeners added
those assigned to element properties (e.g.,
node.onclick = someFunction). Additionally, for a
<canvas> element, the painted image is not copied.
cloneNode() may lead to duplicate element IDs
in a document!
If the original node has an
id attribute, and the clone
will be placed in the same document, then you should modify the clone's ID to be
name attributes may need to be modified also,
depending on whether duplicate names are expected.
To clone a node to insert into a different document, use
|DOM Standard (DOM)|
BCD tables only load in the browser