Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all bindings of an element (with jQuery)

Is there a way to list all bindings on a jQuery element? jQuery's bind() does only seem to attach them and I didn't find a jQuery function that does get the bindings.

like image 322
Zardoz Avatar asked Nov 09 '10 20:11

Zardoz


2 Answers

This answer applies to jQuery version < 1.8

Best way to do that, probably the FireQuery plugin for FireFox. Really a neat tool.

If you want/need to accomplish that "in-code", use jQuerys .data('events') object.

$.each($('#element').data('events'), function(i, e) {     console.log(i, e); }); 

All events that were bound via jQuery gets pushed into that object. Of course, there might also be other event handlers like on-anything, for which you would have to check explicitly.

Ref.: FireQuery

like image 122
jAndy Avatar answered Oct 17 '22 04:10

jAndy


As of jQuery 1.8 the new syntax is:

$.each($._data("#element", "events"), function(i, e) { console.log(i, e); }); 

Note that it's $._data("#element" NOT $.data($("#element"), so be sure to unwrap your selector if you need to using $myJQuerySelector[0].

Read more...

like image 43
Grinn Avatar answered Oct 17 '22 04:10

Grinn