How to find events bound on an element with jQuery


JavaScript

If you need to find a way to get the list off all the events bound on an element here is a code that you can use.

My example cover event delegation just to show how these events are displayed in the console.

.

jQuery("myelemnt").on({
	click: function(){ console.log("click") },
    mouseout: function(){ console.log("mouseout") }
});

//test event delegation
jQuery("myelemnt").on("click","a", function(){
	console.log("a click");
 });
jQuery("myelemnt").on("mouseout","a", function(){
	console.log("a mouseout");
});

//for jQuery 1.8 +
var $events = jQuery._data(jQuery("myelemnt")[0], "events" );
//for jQuery 1.7 and below
//var $events = jQuery('myelemnt').data('events');

//validate if the element has an event attached
if(typeof $events != "undefined"){
	//iteration to get each one of the handlers
	jQuery.each($events, function(i, event){
		jQuery.each(event, function(i, handler){
			console.log(handler); // write on console the handler
		});
	});
}

Output example:

events

Useful links:

I really hope you find this information useful.