How to debug event listeners with your browser’s developer tools

When you’re working with a UI, you may sometimes need to figure out what event (and subsequent callback function) is being triggered by an interaction with an element.
For example, on the homepage for my site, there’s a newsletter signup form. When you click the Get Daily Developer Tips button, what happens?
Today, I’m going to show you how to use your browser’s developer tools to debug event listeners. Let’s dig in!


This content originally appeared on Go Make Things and was authored by Go Make Things

When you’re working with a UI, you may sometimes need to figure out what event (and subsequent callback function) is being triggered by an interaction with an element.

For example, on the homepage for my site, there’s a newsletter signup form. When you click the Get Daily Developer Tips button, what happens?

Today, I’m going to show you how to use your browser’s developer tools to debug event listeners. Let’s dig in!

Right click > inspect element

On the page, right-click the element you want to debug event listeners for, then click Inspect Element.

A screenshot of the Go Make Things homepage, with MS Edge's developer tools open to the event listener tab for the newsletter submit button

In chromium-based browsers like MS Edge and Google Chrome, click the Event Listeners tab in Developer Tools. There, you’ll see a list of all of the events being listened to on that element.

If you expand the event, you can see what element they’re attached to (because of event delegation), and click a link to open up the actual event listener itself in the JavaScript.

A screenshot of the Go Make Things homepage, with Firefox's developer tools open to elements tab for the newsletter form, with the event details showing

In Firefox, events are only surfaced on the element they’re attached to. It doesn’t account for event delegation.

Using my newsletter form as an example, the button element has no events attached to it, but the parent form has a submit event listener. Clicking on the event chicklet next to the form element in the Inspect Element tab reveals the event details, including the callback function that’s run in response.

Other practical uses

In chromium’s developer tools, you can also remove attached events.

This is particularly useful when forms prevent you from pasting in you passwords, account numbers, and such, which makes using a password manager much more difficult.


This content originally appeared on Go Make Things and was authored by Go Make Things


Print Share Comment Cite Upload Translate Updates
APA

Go Make Things | Sciencx (2021-10-18T14:30:00+00:00) How to debug event listeners with your browser’s developer tools. Retrieved from https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/

MLA
" » How to debug event listeners with your browser’s developer tools." Go Make Things | Sciencx - Monday October 18, 2021, https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/
HARVARD
Go Make Things | Sciencx Monday October 18, 2021 » How to debug event listeners with your browser’s developer tools., viewed ,<https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/>
VANCOUVER
Go Make Things | Sciencx - » How to debug event listeners with your browser’s developer tools. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/
CHICAGO
" » How to debug event listeners with your browser’s developer tools." Go Make Things | Sciencx - Accessed . https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/
IEEE
" » How to debug event listeners with your browser’s developer tools." Go Make Things | Sciencx [Online]. Available: https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/. [Accessed: ]
rf:citation
» How to debug event listeners with your browser’s developer tools | Go Make Things | Sciencx | https://www.scien.cx/2021/10/18/how-to-debug-event-listeners-with-your-browsers-developer-tools/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.