jQuery - append/replace event listeners (when event handlers are not known)

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

  • I have lots of UI elements (buttons, hyperlinks etc) that have native events attached to them (eg, clicking a link executes a function)
  • I do not have access to those event listeners, nor I know what functions/handlers need to be Invoked
  • I would like to do a generic function which would: o transverse thru DOM, find the UI elements like button or hyperlink, and attach additional listeners to it that would execute the same handlers/functions (eg, I want to attach “touchend” listeners that would execute the same handlers/functions as “click” event)

Is there a way for me to somehow find out what event handler(s) is(are) used for a particular UI element, and then append the new listener for same handler via .on() method?

Answers


Hiya even though your quandary is bit open ended, hope this helps your cause :)

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

You can access all event handlers bound to an element (or any object) through jQuery’s event storage:

// 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. - I would recommend to know your DOM better but above should help. B-)


Need Your Help

IE7 ignoring margin in a div following an absolute positioned div

html css internet-explorer internet-explorer-7

I have two divs inside a container, the first one has absolute positioning. In ie7, the second div apparently ignores the top margin. Padding seems to work fine, but for visual reasons I have to use

Get tweets that have a specific keyword and other optional keywords in python

python twitter

I am trying to filter real-time tweets from twitter, I have this list keywords=["Alex", "love","hate","hungry","happy"] I want to get tweets that has "Alex" and at least one keyword from given list...