Possible Duplicate:
test if event handler is bound to an element in jQuery
Tried to do the following (link is jQuery object of ‘a’ tag):
link.data("events") //undefined even if link has event handlers
jQuery.data(link, 'events') //undefined always also
jQuery._data(link, 'events') //undefined always also
using jquery-1.8.3
So, how to check if element has click handler?
You can use
jQuery._datato check for events. The first argument should be a reference to the HTML element, not the jQuery object.Sample below.
Also note that this method for checking events will only work when the event is bound via jQuery. If the event is bound via
element.attachEventListener,element.onclick,<a onclick="doStuff()">or any other non jQuery way, this will not work. If you’re fitting into this boat, check this answer.