How to find event listeners on a DOM node using JavaScript

前端 未结 4 1353
梦谈多话
梦谈多话 2020-12-29 05:18

I still can\'t belive this is not possible but is there a way to loop through the dom and see all event handlers attached using \'addEventListener\'. This post and many othe

4条回答
  •  猫巷女王i
    2020-12-29 06:02

    Console of Chrome has a method that can help you check if a dom node has any event listeners registered, for example to check event listeners attached to the document node use:

    https://developers.google.com/chrome-developer-tools/docs/commandline-api#geteventlistenersobject

    getEventListeners(document);
    

    You could recursively iterate over all dom nodes and find all event handlers attached if needed.

提交回复
热议问题