admin管理员组

文章数量:1415099

Is there a easy way to find all js events that are associated with a specific HTML element using Chrome?

Example:

HTML element

<a href="#" class="cancel_link refresh_page">Cancel</a>

Script:

<script type="text/javascript">
    $(function () {
       $(".cancel_link").click(function () {
          //do something
       });

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

</script>

Is there a easy way to find all js events that are associated with a specific HTML element using Chrome?

Example:

HTML element

<a href="#" class="cancel_link refresh_page">Cancel</a>

Script:

<script type="text/javascript">
    $(function () {
       $(".cancel_link").click(function () {
          //do something
       });

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

</script>
Share Improve this question asked May 21, 2014 at 0:02 Diego CotiniDiego Cotini 1,0692 gold badges18 silver badges27 bronze badges 1
  • Right-click element, Inspect Element, in Chrome Developer Tools, in the right pane you will see 'Styles', 'Computed', and 'Event Listeners'. That lists all events for an element. – webketje Commented May 21, 2014 at 0:06
Add a ment  | 

3 Answers 3

Reset to default 3

Find the html element in the Elements panel of the dev tools. Then click the Event Listeners tab in the right panel. In the top right hand corner of that Event Listeners panel there's a filter icon. When you click on it you can choose "All Nodes" (default) or "Selected Node Only".

  • Press F12 to open Developer Tools
  • Click the Elements tab
  • Select the element you with to analyze
  • On the right hand side click the Event Listeners tab

From that tab you can view all of the handlers bound to the element for each event.

Since you seem to use jquery, here is a previously posted solution:

// Bind up a couple of event handlers
​$("#foo").on({
    click: function(){ alert("Hello") },
    mouseout: function(){ alert("World") }
});​​​

// Lookup events for this particular Element
​$._data( $("#foo")[0], "events" );

you can find out more here: Can I find events bound on an element with jQuery?

本文标签: javascriptFinding all js events associated with a HTML element using ChromeStack Overflow