How can I reliably kill every jQuery event wired up, regardless of event type, handler or DOM element
Using the fantastic (yet cruelly not accepted) post on this question: List all javascript events wired up on a page using jquery I have discovered that it's possible to query the jQuery events cache to read the events that are wired up, what they're wired up to and so on.
I also have Visual Event, a bookmarklet which overlays event bindings onto the actual HTML elements on screen.
What I need now - to test the impact of the events which are hooked up on my page, is to literally unbind, kill, die (etc) every single event which jQuery knows about - b开发者_StackOverflowut this seems to be tricky to achieve without knowing all of the context (e.g. selector, handlers) - the reason is to test the "general" page performance, filling in forms, scrolling around, collapsing/expanding stuff and so on.
I can potentially 'roll my own' script to do this, using the script in the question I posted above to get all the items and then removing them - but I'm not sure if this is possible, or the best way to go around it - I hope that I'm re-inventing a pre-existing wheel by suggesting this.
What I really want/need is:
$(document).removeAllEventsThatAreWiredUpToAnything();
...but I know it does not exist.
Is there an easy way to do this? Disabling JavaScript is not really an option as my pages are built fairly extensively with ajax calls that fire when loading up, so it wouldn't be that useful a test.
More than happy to take/accept solutions rather than direct answers - just need to gather some understanding of performance impact of event overuse in the quickest possible way.
Regards -SB
This:
$('*').unbind();
will unbind all event types for all elements.
精彩评论