JQuery - add / replace event listeners (when event handlers are unknown)

I tried to find the answer to my problem, but was not successful - apologies if the answer is very obvious :). Here is the premise of the problem I'm trying to solve.

  • I have many interface elements (buttons, hyperlinks, etc.) to which native events are attached (for example, clicking on a link performs a function)
  • I do not have access to these event listeners, and I do not know what functions / handlers should be called.
  • I would like to make a general function that: o cross-section through the DOM, find user interface elements, such as a button or a hyperlink, and connect additional listeners to it that will perform the same handlers / functions (for example, I want to attach listeners " touchhend "which will perform the same handlers / functions as the" click "event)

Is there a way for me to somehow find out which event handlers are used (used) for a specific user interface element, and then add a new listener for the same handler using the .on () method?

+2
source share
1 answer

, , , :)

- , , , JQuery = http://james.padolsey.com/javascript/things-you-may-not-know-about-jquery/

, ( ) jQuerys:

// List bound events:
console.dir( jQuery('#elem').data('events') );

// Log ALL handlers for ALL events:
jQuery.each($('#elem').data('events'), function(i, event){
    jQuery.each(event, function(i, handler){
        console.log( handler.toString() );
    });
});

// You can see the actual functions which will occur
// on certain events; great for debugging!

P.S. - DOM, . B-)

0

All Articles