Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 759
apelliciari Avatar asked Nov 13 '09 14:11

apelliciari


People also ask

How do you get event listeners of elements?

Right-click on the search icon button and choose “inspect” to open the Chrome developer tools. Once the dev tools are open, switch to the “Event Listeners” tab and you will see all the event listeners bound to the element. You can expand any event listener by clicking the right-pointing arrowhead.

Which jQuery keyword should be used to bind an event to an element?

bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.

What is event binding in jQuery?

The jQuery bind() event is used to attach one or more event handlers for selected elements from a set of elements. It specifies a function to run when the event occurs. It is generally used together with other events of jQuery. Syntax: $(selector).


1 Answers

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);
like image 198
jantimon Avatar answered Oct 20 '22 00:10

jantimon