I would like to reset the DOM to original state and then manipulate it again.
I have found that the best way to do this is as follows:
// Clone the Dom and assign it to a variable
divClone = $("#document").clone();
// .... More Code ......
// When required, replace the DOM with with the cloned variable.
$("#document").replaceWith(divClone);
The only problem is that you cannot manipulate the newly reseted DOM again.
I have put together a JSFiddle which uses a simple example of adding a class. You can click on the "test" link to add a a class. You can then click on "Reset" to return the DOM back to its original state. However, if you click on the "test" link again, no more classes will be added to the restored DOM. (Obviously, this is just a simplified example. There are better ways of removing and adding classes).
How can I manipulate the restored DOM?