Skip to content
jshacks.dev
Debugging

Find which listener handles an event in DevTools

See every handler on an element and open its source in Chrome DevTools using the Event Listeners tab, including delegated handlers from ancestors.

1 min read
Summarize in AI

A click on a button does something, and you cannot tell which function handles it. The Elements panel lists the listeners attached to the selected element.

HTML
<ul id="menu">
  <li><button id="save">Save</button></li>
</ul>
<script>
  document.querySelector("#menu").addEventListener("click", function onMenuClick(e) {
    if (e.target.id === "save") console.log("saving");
  });
</script>

Select the button and open the Event Listeners tab in the side pane. By default it shows only listeners on the node itself, so the list may be empty here, because the handler lives on the ul element. Tick Ancestors to include handlers from parents, which is the delegation case:

Text
click
  ul#menu   script.html:4

Click the file link, and the Sources panel opens at the handler. Event delegation is why the listener is on a parent. The tab is documented in the DevTools Elements reference.

Frameworks register their own listeners, which can bury yours. Untick Framework listeners to hide the ones that DevTools can identify as library code.

Share

More snippets

Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read
Debugging

Inspect an object with console.dir

Show nested objects beyond the default depth of two with console.dir and the depth option, instead of the [Object] placeholders console.log prints.

1 min read
Debugging

Debug a single Vitest test in VS Code

Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.