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

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章