I think you should use this method overload . clone () :
$element.clone(true, true);
clone ([withDataAndEvents] [, deepWithDataAndEvents])
withDataAndEvents : A Boolean value that indicates whether event handlers and data should be copied along with the elements. The default value is incorrect.
deepWithDataAndEvents : A Boolean value indicating whether to copy event handlers and data for all children of the cloned element. By default, its value corresponds to the first argument (the default value is false).
Remember that .on() does not actually associate events with goals, but with the element to which you are delegating. Therefore, if you have:
$('#container').on('click', '.button', ...);
Events are actually tied to #container . When a .button element is .button , it bubbles up to the #container element. The element that triggered the event is evaluated by the .on() selector parameter, and if it matches, an event handler is executed. This is how event delegation works.
If you clone the #container element, you need to deeply clone events and data for the bindings made using .on() to save.
This would not be necessary if you used .on() for the parent of #container .
Didier Ghys Mar 03 2018-12-12T00: 00Z
source share