Can I get a list of events related to an element in jQuery?

As the question said, I need a list of events related to a specific element.

I mean events like a click, mouseover, etc., associated with this element when loading dom.

Example

(stupid):

$("#element").click(function()
{
    //stuff
});
$("#element").mouseover(function()
{
    //stuff
});
$("#element").focus(function()
{
    //stuff
});

Result:

click, mouseover, focus

+5
source share
2 answers

Each event is added to the array.

This array can be obtained using the jQuery data method:

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

To record all events of a single object in fireBug, simply type:

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

And you will get a list of all related events.


Update:

For jQuery 1.8 and above, you should examine the internal jQuery data object:

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

element.data('events');. :

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.
    }
}
+2

All Articles