22

Is there any way to see what events are bound to an element with jQuery?

Péter Török
  • 114,404
  • 31
  • 268
  • 329
Adrian Crapciu
  • 265
  • 1
  • 3
  • 5

3 Answers3

29

If you are using Safari or Chrome, you can open up the Developer Tools and inspect the element (by clicking the magnifying glass). In the Event Listeners tab on the right it will tell you the binded events to that element, with their functions and locations.

OR to do this via code:

$('selector').data('events'); // get
console.dir($('selector').data('events')); // display in firefox firebug or webkit's developer tools
balupton
  • 47,113
  • 32
  • 131
  • 182
  • 1
    I've updated my question to include a code example to see the attached events. – balupton Jul 20 '10 at 08:45
  • The developer tools from Chrome does it display the events binded with jQuery? – Adrian Crapciu Jul 20 '10 at 08:54
  • Yep. Here is a screenshot: http://img830.imageshack.us/img830/1372/tmpu.png I've also included in my answer how to fetch the listeners using javascript, so you don't need to use a browser console. – balupton Jul 20 '10 at 09:11
  • @Adrian - Make sure to accept this as the answer if it answered your question via the checkmark on the left :) – Nick Craver Jul 20 '10 at 09:56
  • 4
    This just isn't working for me. I'm only getting undefined returned when I call .data('events') on elements that clearly have events assigned to them. Any idea what could be wrong?? – Ryan Delucchi Mar 08 '11 at 21:47
  • Ryan ask it in a new question and attach a link here :) – balupton Mar 08 '11 at 23:59
8

This solution is obsolete in new jQuery versions. You must use:

 $._data($('selector')[0],'events')
0

If you don't need this in script, you can check that element in any DOM inspection tool like Firebug and see all events.

Māris Kiseļovs
  • 16,957
  • 5
  • 41
  • 48