views:

56

answers:

3

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
+1 excellent answer.
Jacob Relkin
very agile method, thanks!
teMkaa
+1  A: 

Have you tried to use FireQuery? Should be installed in everybody's Firefox/Firebug setup.

Marcel J.
+1  A: 

Check out VisualEvent

fudgey
great lib! but it's ui has some troubles with closely placed elements. Thanks!
teMkaa