but you can still use $._data($(elem).get(0), "events")
– bullgareAug 18 '12 at 11:01

10

blog.jquery.com/2011/11/08/building-a-slimmer-jquery .data(“events”): jQuery stores its event-related data in a data object named (wait for it) events on each element. This is an internal data structure so in 1.8 this will be removed from the user data name space so it won’t conflict with items of the same name. jQuery’s event data can still be accessed via jQuery._data(element, "events") but be aware that this is an internal data structure that is undocumented and should not be modified.
– Sam GreenhalghAug 20 '12 at 3:41

13

This is no longer valid. As of 1.9 this has been removed.
– oligofrenApr 3 '13 at 8:33

15

Really? It's working for me with 1.10/2.0 for me.
– podpersonJul 24 '13 at 19:40

This is the correct answer. The crucial bit is the second half. This helped me find an issue in under a minute that would have taken over an hour if I had to search through all the code. Thank you!
– Andrew EnsleyDec 29 '10 at 19:58

2

Works with 1.4, but not in jQuery 1.8.2.
– Timo KähkönenDec 21 '12 at 21:15

15

For jQuery 1.8+, you must use the 'private data' method: jQuery._data( jQuery("#el")[0], "events" ); instead of the 'public data' method: jQuery("#el").data("events"). The events object hasn't actually been stored in .data() for a long time, we trimmed a few bytes of code out by removing this "proxy" from the "public API"
– gnarfJan 10 '13 at 17:13

FWIW - Pointing out that it 'internally' calls the other data function with a parameter we specifically don't document probably isn't needed. But yes, jQuery._data( element, "events" ) is the 'correct' way to get this information now.
– gnarfJan 10 '13 at 17:11

To use it you just have to include findHandlersJS (or just copy&paste the raw javascript code to chrome's console window) and specify the event type and a jquery selector for the elements you are interested in.

For your example you could quickly find the event handlers you mentioned by doing

events
Array with information about the jquery event handlers for the event type that we are interested in (e.g. click, change, etc)

handler
Actual event handler method that you can see by right clicking it and selecting Show function definition

selector
The selector provided for delegated events. It will be empty for direct events.

targets
List with the elements that this event handler targets. For example, for a delegated event handler that is registered in the document object and targets all buttons in a page, this property will list all buttons in the page. You can hover them and see them highlighted in chrome.

As of 1.9 there is no documented way to retrieve the events, other than to use the Migrate plugin to restore the old behavior. You could use the _.data() method as jps mentions, but that is an internal method. So just do the right thing and use the Migrate plugin if you need this functionality.

Prior to 1.9, .data("events") could be used to retrieve jQuery's
undocumented internal event data structure for an element if no other
code had defined a data element with the name "events". This special
case has been removed in 1.9. There is no public interface to retrieve
this internal data structure, and it remains undocumented. However,
the jQuery Migrate plugin restores this behavior for code that depends
upon it.

The accepted answer also clearly shows the new, correct way to get it for recent versions: jQuery._data( elem, "events" );...
– IanMay 23 '13 at 21:21

1

A private, undocumented way will never be a correct way. The correct way - meaning documented, public, and intended - is to use the Migrate plugin.
– oligofrenMay 27 '13 at 9:49

3

You seem to misunderstand the point of the Migrate plugin. jQuery removed deprecated features, and the Migrate plugin is to help migrate developer's code to the newer versions so that they can immediately take advantage of new features and improvements, but not lose functionality. It's meant to help the coder see what they need to do in order to start properly using new versions of jQuery. You shouldn't use it in production to restore features. Also, many things aren't documented and up to date in jQuery documentation - they've pointed it out before, so that's not a reason
– IanMay 28 '13 at 15:17

Note that this will only work with direct event handlers, if you are using $(document).on("event-name", "jq-selector", function() { //logic }), you will want to see the getEvents function at the bottom of this answer

I have to say many of the answers are interesting, but recently I had a similar problem and the solution was extremely simple by going the DOM way. It is different because you don't iterate but aim directly at the event you need, but below I'll give a more general answer.

I had an image in a row:

<table>
<td><tr><img class="folder" /></tr><tr>...</tr></td>
</table>

And that image had a click event handler attached to it:

imageNode.click(function () { ... });

My intention was to expand the clickable area to the whole row, so I first got all images and relative rows:

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).