views:

48

answers:

2

Hi,

I'm looking through a plugin that somebody else has written and for some reason all my click event handlers are destroyed. I'm going through the code and there are several uses of unbind which I've commented out to determine whether it is causing the issue. Unfortunately that is not enough, so I'm wondering if there are other ways to remove/destroy event handlers?

Thanks!

A: 

There is .unbind() which will unbind a collection's event once, or .die() which is the opposite of .live(), meaning it will unbind the collection's event that is currently set, and any events that are attached in the future.

Michal
I checked out die() and there's no use of die in the code...
Steven Cheng
Are you doing any DOM manipulation for the elements with .click() events? If you use .remove(), then event handlers aren't saved. If you use .detach(), then you need to make sure you are caching the removed elements.
Michal
I'm not doing any direct DOM manipulation in my own code, however when I execute $($.plugin).remove() that is when my click events are being removed.
Steven Cheng
A: 

Check for instances of removeData(). If it is called without a parameter, it will erase all data (including event handlers) for the element.

http://api.jquery.com/removeData/

or $(element).removeData('events');

or some other $(element).data('events'); or $(element).data().events; manipulation

RightSaidFred
thanks, there's no removeData or event manipulation either however you've given me a good idea on how to debug the issue by stepping through the code...
Steven Cheng
@Steven - Also check for calls to `.remove()` and `.empty()` since they also clean up data.
RightSaidFred
There's no references to .empty(), however .remove() is used quite a bit.. I'm avoiding going through each .remove() just to find the one causing my problems...
Steven Cheng