How to list all registered events of a DOM node using JavaScript?

前端 未结 7 2797
臣服心动
臣服心动 2021-02-19 16:50

I can add or remove an event handler for a DOM node. Is it possible to find out all the registered events handlers of a given DOM node? I am referring to straight Javascript mea

相关标签:
7条回答
  • 2021-02-19 17:01

    If your interest is to discover some event, in order to disable it - I came here because of that - I recommend to use the Firebug extension, with Mozilla Firefox. Selecting the part of the document, you are interested in, look at the right panel, the Events tab: you will see all events, and can even disable them.

    0 讨论(0)
  • 2021-02-19 17:03

    I know this is an old question, but just in case, for chrome you can use getEventListeners

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

    as mentioned here:

    https://stackoverflow.com/a/17466308/538752

    0 讨论(0)
  • 2021-02-19 17:11

    Also, in Google Chrome, please select the element and notice the number, it will show you $0 or any other number.

    Then in console, type this code and press enter.

    getEventListeners($0)
    

    and then you will see the result. Please see the image below for more elaboration.

    0 讨论(0)
  • 2021-02-19 17:14

    DOM Level 3 specifies eventListenerList - however, I'm not aware of any DOM implementation which supports this - or any other reliable way to list the event listeners. It seems to have been an oversight to this point.

    0 讨论(0)
  • 2021-02-19 17:20

    Visual Event can show you which events are registered, but it only works with DOM level 0 attached events; the W3C level 2 implementation as well as the Internet Explorer proprietary method are not supported and/or cannot be retrieved.

    0 讨论(0)
  • 2021-02-19 17:23

    This works for Chrome/Safari console:

    getEventListeners(document.getElementByID('myElementId'));
    
    0 讨论(0)
提交回复
热议问题