Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

test if event handler is bound to an element in jQuery [duplicate]

Is it possible to determine whether an element has a click handler, or a change handler, or any kind of event handler bound to it using jQuery?

Furthermore, is it possible to determine how many click handlers (or whatever kind of event handlers) it has for a given type of event, and what functions are in the event handlers?

like image 344
Elias Zamaria Avatar asked Aug 05 '09 22:08

Elias Zamaria


1 Answers

You can get this information from the data cache.

For example, log them to the console (firebug, ie8):

console.dir( $('#someElementId').data('events') ); 

or iterate them:

jQuery.each($('#someElementId').data('events'), function(i, event){      jQuery.each(event, function(i, handler){          console.log( handler.toString() );      });  }); 

Another way is you can use the following bookmarklet but obviously this does not help at runtime.

like image 89
redsquare Avatar answered Sep 29 '22 03:09

redsquare