Your code works as expected, the problem is that the DOM you cloned does not have handlers associated with it.
You have 2 options, the first is to clone after all the handlers are bound by passing true to the withDataAndEvents clone method argument:
$(".test").click(function() { $("#document").addClass("green"); }); $(".reset").click(function() { $("#document").replaceWith(divClone.clone(true)); }); var divClone = $("#document").clone(true);
Fiddle
The second option is to use event delegation .
var divClone = $("#document").clone(); $(document).on('click', '.test', function() { $("#document").addClass("green"); }).on('click', '.reset', function() { $("#document").replaceWith(divClone.clone()); });
Fiddle
The disadvantage of this second approach is that all events must bubble up to the document level, and you cannot cancel the bubbling with event.stopPropagation() .
Edit: An updated response to replace a clone with a clone so that the original clone is always in a safe state in its original state and can serve as a basis for subsequent drops.
source share