Reputation: 13194
Is it possible to undo last DOM modification?
I've tried to remember state after any change by
undoArray = [ $("#container").clone() ];
//some situation when dom changed and remember state
undoArray.push( $('#container').clone() );
And then, if needed, to restore #container
content from this array, but it was loosing all events attached directly to elements.
Upvotes: 2
Views: 289
Reputation: 3543
Pass true
to .clone()
to keep events and data.
undoArray = [ $("#container").clone(true) ];
Docs for .clone()
Just remember to clean the data if you're going to destroy an item in the Array without putting it in the DOM.
Upvotes: 3
Reputation: 22619
If you want to persist the events then pass true
for clone() withDataAndEvents
$("#container").clone(true)
or attach using on() to the document
$(document).on('eventName','targetSelector', eventHandler);
Upvotes: 1