2

In jquery, we can clone an element and all its events with clone() method. Example:

$(".element").clone(true);

How can we do the same thing with native Javascript?

I'm updating my post.

Thanh Nguyen
  • 5,174
  • 11
  • 43
  • 74

1 Answers1

2

You can try like this:

myelement = oldelement.cloneNode(deep)

From MDN:

The Node.cloneNode() method returns a duplicate of the node on which this method was called.

deep Optional

true if the children of the node should also be cloned, or false to clone only the specified node.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331