Curtis
Curtis

Reputation: 103348

How can I find what click events are linked to a jQuery selector?

If I have the following HTML markup:

<div class="foo">bar</div>

How can I find which click events are linked to this element / jQuery selector?

Is there a way I can get a list of file locations or something using Google Chrome Console?


Say I have the following jQuery:

$(".foo").click(function(){
  //do something
});

$("div").click(function(){
  //do something else
});

$("table").click(function(){
  //do something else
});

I would want something like:

foobar.js (line 1)

foobar.js (line 4)

Upvotes: 1

Views: 200

Answers (2)

Emil
Emil

Reputation: 380

There is something called Visual Event. You can know all event handlers attached to DOM elements.

Upvotes: 0

Om3ga
Om3ga

Reputation: 32863

This code should help. It is based on this link. Is this what you want?

// 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() );
    });
});

Upvotes: 3

Related Questions