Vivien
Vivien

Reputation: 1169

List all jquery event binded on an dom element

I'm working on a spaghetti coded website. Some strange action apears on certain elements. There is nothing listed on the Chrome event listener.

Is there any other way to look at that ? Like writing in the console something like that:

$('#myElement').getEvents(); //Not a real code

Upvotes: 3

Views: 461

Answers (1)

Brad Christie
Brad Christie

Reputation: 101614

As another option, you can get between the jQuery binding and the element using the following hook:

(function($){
    var event_add_orig = $.event.add;
    $.event.add = function(){
        console.log('Added event (' + arguments[0].tagName + '::' + arguments[1] + ')');
        // arguments[0] // elem
        // arguments[1] // types
        // arguments[2] // handler
        // arguments[3] // data
        // arguments[4] // selector
        event_add_orig.apply(this, arguments);
    };
})(jQuery);

That way you'll see every binding being applied throughout the page. You can then use more logic to distill it down to a specified event or element. Keep in mind that this would need to be defined before anything else on the page executes, but of course after jQuery's defined.

Upvotes: 1

Related Questions