view event handlers in Chrome

Chrome developer tools can be used to view event handlers/listeners on any element in an html page. This is pretty handy to quickly view event handlers on a site without going into its javascript or html code. Here are the quick steps to achieve this:

  1. We’ll use the following html code for the purpose of this article:
    <!doctype html>
    <html>
    <head>
    <title>Chrome developer tools - view event listeners example</title>
    </head>
    <body>
    <h1>Chrome developer tools - view event listeners example</h1>
    <a href="" onclick="alert('foo'); return false;">clickme</a>
    </body>
    </html>
    
    You can see the live example html page at Chrome developer tools – view event listeners example.
  2. First right click on the element you want to see event listeners for. Here we’ll right click on link “clickme”. Then click on inspect element as shown below:
    chrome-right-click-inspect-element
  3. This will open up chrome developer tools. Make sure element tab is selected.
    chrome-developer-tools-element-selected
  4. In the right panel click on even listeners. Click on click event and then click on node “a”. To view the javascript code, you can mouseover the listenerBody function snippet as shown below:
    chrome-developer-tools-event-listeners
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments