开发者

How can I see which jQuery function is bound to the element?

开发者 https://www.devze.com 2022-12-28 21:24 出处:网络
I found a site, which has some function that I need, in javascript. It\'s using jQuery, when I click antag, some function is executed, so jQuery sets a bind fortag. But ho开发者_StackOverflow中文版w c

I found a site, which has some function that I need, in javascript. It's using jQuery, when I click an tag, some function is executed, so jQuery sets a bind for tag. But ho开发者_StackOverflow中文版w can I find out which function is bound with it? Firebug didn't show it to me :(


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);
  });
});


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号