How to find event listeners on a DOM node in JavaScript or in debugging?

How to find event listeners on a DOM node in JavaScript or in debugging?

回答1

Chrome, Firefox, Vivaldi and Safari support getEventListeners(domElement) in their Developer Tools console.

For majority of the debugging purposes, this could be used.

Below is a very good reference to use it:
getEventListeners function


Highly voted tip from Clifford Fajardo from the comments:

getEventListeners($0) will get the event listeners for the element you have focused on in the Chrome dev tools.

评论
TIP: getEventListeners($0) will get the event listeners for the element you have focused on in the Chrome dev tools. I use this all the time. Love not having to use querySelector or get__By_ functions Jan 31, 2017 at 23:46

 

回答2

 

Update 2022:

In the Chrome Developer Tools, in the Elements panel, there is the Event Listeners tab, where you can see listeners for the element.

You can also unselect "Ancestors" so it only shows the listeners for that element

 

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-11-20 11 JavaScript Utility Libraries you Should Know in 2019
2019-11-20 The Five Qualities You Need in a Partner
2018-11-20 DataContractAttribute.IsReference
2014-11-20 sqlite的Top筛选
点击右上角即可分享
微信分享提示