3

Possible Duplicate:
Inspect attached event handlers for any DOM element

Is there a tool - such as a browser extension, jQuery console script, bookmarklet or Firebug plugin - that displays all events that can be fired by a particular DOM element, and include any event handlers currently listening to those events?

Community
  • 1
  • 1
Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
  • Good call KennyTM - didn't spot that, however if possible I'd like to keep this open to see if there have been any new developments since that question was asked. – Chris Fulstow Aug 09 '10 at 07:13
  • @ChrisFulstow Any new developments can go in the other thread perfectly fine. – James Khoury Nov 13 '12 at 04:49

2 Answers2

3

You are looking for:

FireQuery

http://firequery.binaryage.com/

To do it your own, you can always access the events data structure from a jQuery object.

Example:

$(document.body).bind('click', function(){
   alert('I am an event handler!');
});

$.each($(document.body).data('events'), function(i,v){
  console.log(i);
  $.each(v, function(i2,v2){
    console.log(' > ', v2.handler.toString());
  });
});

That would list all events into your FireBug/Webkit console and print it's event handler functions as plain text. You can remove the .toString() part or just log v2 the get more detailed information.

update

Like Anurag commented, that will show you only handlers which were bound through jQuery. It will not lookup up addEventhandler() / addHandler or inline-event handlers.

You can lookup inline-event handlers by checking for the on-xxx attribute. DOM level3 does implement hasEventListenerNS, but I don't think any browser uses those yet.

jAndy
  • 231,737
  • 57
  • 305
  • 359
1

Chrome's built-in developer bar shows event handlers bound to a particular DOM element, but it doesn't list events that don't have handlers already bound to them.

David Tang
  • 92,262
  • 30
  • 167
  • 149
  • +1 - Also what do you mean by - "but it doesn't list events that don't have handlers already bound to them"? If an event, say - "keydown", has no handlers, then it won't be listed, which is rather obvious in any case. – Anurag Aug 09 '10 at 07:18
  • @Anurag- I had the same thought, but the OP asked that it "displays all events that CAN be fired", which I assumed to be for reference purposes – David Tang Aug 09 '10 at 07:24