The Node.cloneNode() method returns a duplicate of the node on which this method was called.
From Mozilla Developer Network:
The
Node.cloneNode()method returns a duplicate of the node on which this method was called.Cloning a node copies all of its attributes and their values, including intrinsic (in–line) listeners. It does not copy event listeners added using
addEventListener()or those assigned to element properties. (e.g.node.onclick = fn) Moreover, for a element, the painted image is not copied.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 usingNode.appendChild()or a similar method. It also has no parent until it is appended to another node.If
deepis set tofalse, child nodes are not cloned. Any text that the node contains is not cloned either, as it is contained in one or more childTextnodes.If
deepevaluates totrue, the whole subtree (including text that may be in childTextnodes) is copied too. For empty nodes (e.g.<img>and<input>elements) it doesn't matter whetherdeepis set totrueorfalse.