i found a site, which has some function that i need, in javascript. It's using jQuery, when i clicking tag, some function has been executed, so jQuery set a bind for tag.. but how i could found wich function is binded for it? Firebug didn't show it to me :(
+7
A:
If you wanted to say see the click
event handler for an element, you'd get the first handler like this:
$("#element").data("events").click[0].handler
This would give you the function running. Here's an example page showing that
Here's an example:
$("a").click(function() {
alert($("a").data("events").click[0].handler);
});
On click, this would alert: function() { alert($("a").data("events").click[0].handler); }
This is just an example using click
, but whatever you need it for works, mouseenter
, focus
, whatever the event may be, including custom events.
As an aside, if you wanted to loop over all event handlers for an element or collection, this would work, just change the selector to what you're after (here's the same example updated to include this):
$.each($("a").data("events"), function(i, e) {
$.each(e, function(j, h) {
alert('Event: ' + i + '\nHandler:\n' + h.handler);
});
});
Nick Craver
2010-04-29 23:47:36
+1 excellent answer.
Jacob Relkin
2010-04-29 23:54:03
very agile method, thanks!
teMkaa
2010-04-30 09:00:10
great lib! but it's ui has some troubles with closely placed elements. Thanks!
teMkaa
2010-04-30 09:03:10