List all live events in jQuery

How can I find in jQuery which events are related to live for a specific element?

Let's say that I have a randomFunction function that returns a random function from an array of functions. How can I find which function was bound to a specific element?

 var arrayOfFunctions = []; //a whole bunch of functions function randomFunction(array){}; //returns one of those functions $('#certain_element').live('click', randomFunction(arrayOfFunctions)); 

What is the index of an array that corresponds to the function associated with live for $('#certain_element') ?

+8
javascript jquery
source share
3 answers

Ok, got it. For the click event, for $('#certain_element') , registering each binding index on the console:

 var relevantHandlers = $.map($(document).data('events').live, function(value){ if(value.origType == 'click' && value.selector == '#certain_element'){ return value.handler; } }; //all handlers for #certain_element bound to click by live. $.each(relevantHandlers, function(){ console.log("the index is: " + $.inArray(this, arrayOfFunctions)); }); 
+3
source share

Check out this plugin . When I last used this, I had to change it a bit for the latest version of jQuery, but it should give you direction.

+1
source share

There is an excellent bookmarklet called Visual Event , which shows the code that will be called.

But since you are actually calling a random function, perhaps something is as simple as turning on a warning ("function name") or colsone.log ("function") if you are just testing.

+1
source share

All Articles