Is there a way to reset the current page ? free all event handlers, remove any CSS toggled by Jquery, in simpler words, restoring the page to the original state without refreshing ?
2 Answers
Well, here's a solution - capture a clone of the body
as it is before you've done anything to it, then when you need the reset, replace the entire body
with this clone.
var original = $('body').clone();
$('#reset').click(function() {
$('body').replaceWith(original);
});
Of course, this won't undo any changes you made elsewhere, such as in the head
, but it's still slightly better than the other options you've got, right?
See: http://jsfiddle.net/uevrM/
Edit: Just realized, this also won't kill off any event handlers created with live
or delegate
. So again, no, this isn't 100% clean.

- 49,435
- 16
- 136
- 136
-
It should take care of `.delegate()` handlers in the sense that they won't fire anymore, since those are attached to their respective containers. What it doesn't do is clear any of the data/event handlers that jQuery stores. It would just disassociate it from the elements, so you would still want to delete that data. It is likely as simple as `delete jQuery.cache;` though. – user113716 Oct 06 '10 at 04:09
refresh/reload page. There's no other way.
I commented to the OP's post.
But thinking of it, I think there's a way.
On the css part, animations are being done on the style
attribute. Removing style
attribute reset the element from the animation. But take note that if you were using style
attribute to style your element, that will be erased too.
On the binding event, you may want to bind namespaced events. For example, binding click would look something like this,
$('#someID').bind('click.toBeRemove', function(){...})
So that removing events would be easy as $('*').unbind('.toBeRemove')
. Leaving the other original events (in this example the click event).
When using plugins, use those that has .destroy()
method which removes it functionality and style on the element.
But this is not 100% sure working. Just a theory. There's NO easy way doing this. - Yes! there's no $(window).reset()
that would reset the page without reloading.

- 64,198
- 21
- 121
- 139
-
Always a good idea to hesitate a bit before giving an "it can't be done" comment/answer. :o) So why the namespacing on the event? – user113716 Oct 06 '10 at 03:24
-
well for my purpose, removing all event handlers by iterating over every element was sufficient. thank you for this answer. – KJW Oct 07 '10 at 23:44