jQuery find events handlers registered with an obj

2018-12-31 01:42发布

I need to find which event handlers are registered over an object.

For example:

$("#el").click(function() {...});
$("#el").mouseover(function() {...});

$("#el") has click and mouseover registered.

Is there a function to find out that, and possibly iterate over the event handlers?

If it is not possible on a jQuery object through proper methods, is it possible on a plain DOM object?

14条回答
还给你的自由
2楼-- · 2018-12-31 02:24

I use eventbug plugin to firebug for this purpose.

查看更多
忆尘夕之涩
3楼-- · 2018-12-31 02:28

For jQuery 1.8+, this will no longer work because the internal data is placed in a different object.

The latest unofficial (but works in previous versions as well, at least in 1.7.2) way of doing it now is - $._data(element, "events")

The underscore ("_") is what makes the difference here. Internally, it is calling $.data(element, name, null, true), the last (fourth) parameter is an internal one ("pvt").

查看更多
登录 后发表回答