tags:

views:

197

answers:

1

Is there a way to temporarily unbind event handlers that were bound via a 3rd party (ie, I didn't bind them myself) and then restore them?

For example, I'm using jQuery UI's tabs.

I'd like to disable all the tabs default bindings until a certain point that I'd then like to bind them back up.

So, for instance:

  • jquery UI creates the tabs and binds the click (and other) events to each tab
  • my script then caches the events for each tab and then unbinds them
  • my script then rebinds the cached events for each tab one by one based on another variable

Unbinding events seems easy enough but I'm not sure how to go about storing the events before I unbind them and then have them accessible later to rebind.

+1  A: 

Add your own handlers to the events before the plugins do.

In your handlers, check whether you want the plugins' handlers to run, and, if you don't wnat them to, call event.stopImmediatePropagation.

SLaks
clever! Trying that now...
DA
works great! THANKS! This is a great tip.
DA