6

As the question said, i need the list of events bound to a specific element.

I mean events like click, mouseover etc bound to that element at the loading of the dom.

(Stupid) example:

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

Result:

click, mouseover, focus

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
apelliciari
  • 8,241
  • 9
  • 57
  • 92

2 Answers2

13

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);
jantimon
  • 36,840
  • 23
  • 122
  • 185
  • 1
    As a note for new visitors: This answer is outdated since jQuery [Version 1.8](http://blog.jquery.com/2011/11/08/building-a-slimmer-jquery/): "*.data(“events”): jQuery stores its event-related data in a data object named (wait for it) events on each element. This is an internal data structure so in 1.8 this will be removed from the user data name space so it won’t conflict with items of the same name. […]*". See also: [jQuery 1.8 find event handlers](http://stackoverflow.com/questions/12214654/jquery-1-8-find-event-handlers) – insertusernamehere Oct 04 '13 at 12:51
2

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.
    }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555