3

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
2
  • 2
    Could be a duplicate of Fetch all binded events using jquery Commented Oct 18, 2012 at 13:34
  • You can try inspecting the ancestor chain to see if any of the #myElement ancestors have bound event listeners. Commented Oct 18, 2012 at 13:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great solution, arguments[2] give me enought info to find the problem. Thx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.