Is it possible to obtain a list of events bound to an element in jQuery?

五迷三道 提交于 2019-12-04 05:48:25

Every event is added to an array.

This array can be accessed using the jQuery data method:

$("#element").data('events')

To log all events of one object to fireBug just type:

console.log ( $("#element").data('events') )

And you will get a list of all bound events.


Update:

For jQuery 1.8 and higher you have to look into the internal jQuery data object:

$("#element").each(function(){console.log($._data(this).events);});
// or
console.log($._data($("#element")[0]).events);

You can access it by element.data('events');. Example:

var events = element.data('events');
for (var type in events) {
    // `type` is "click", "mouseover", "change", etc.
    for (var handler in events[type]) {
        // `handler` is the associated function.
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!