jQuery 1.8 find event handlers
Asked Answered
C

2

21

How to find event handlers on an object in jQuery 1.8+?

var func = function(){ alert(1); };
var obj = $('#obj');
obj.on("click", func);
// obj.data('events') is undefined
Cosmonaut answered 31/8, 2012 at 11:43 Comment(1)
seems like a good question, you can test it on this js fiddle jsfiddle.net/968jjAniline
J
30

Use the data function as is done by jQuery internally.

On previous versions, you could call it like for other data :

obj.data('events');

In jQuery 1.8, this direct access was removed, so in recent versions you must call it like this :

$._data(obj[0], "events")

You can see it in action by opening the console in this fiddle : http://jsfiddle.net/8TpeP/2/

Jural answered 31/8, 2012 at 11:45 Comment(1)
Thank you. Learned it today. Only knew the pre 1.8 method till now.Flamen
F
5

to find event handlers of an element in jQuery 1.8+ you've got to do this way:

$._data($("YOUR-SELECTOR-HERE").get(0), "events")

Fettling answered 7/11, 2013 at 16:32 Comment(1)
or briefly: $._data($("YOUR-SELECTOR-HERE")[0], "events")Celebrate

© 2022 - 2024 — McMap. All rights reserved.