How to find event listeners on a DOM node when debugging or from the JavaScript code?

前端 未结 19 2831
臣服心动
臣服心动 2020-11-21 05:34

I have a page where some event listeners are attached to input boxes and select boxes. Is there a way to find out which event listeners are observing a particular DOM node a

19条回答
  •  孤城傲影
    2020-11-21 06:10

    To get all eventListeners on a page printed alongside their elements

    Array.from(document.querySelectorAll("*")).forEach(e => {
        const ev = getEventListeners(e)
        if (Object.keys(ev).length !== 0) console.log(e, ev)
    })
    

提交回复
热议问题