Tried to search online, but does not look like I can formulate search query properly.
How can I, either with jQuery or just javascript list all the handlers or event listeners that are attached to element(s)/document/window or present in DOM?
To check if an element has event listener on it with JavaScript, we can call the getEventListeners function in the Chrome developer console. getEventListeners(document. querySelector("your-element-selector")); in the Chrome developer console to select the element we want to check with querySelector .
Right-click on the search icon button and choose “inspect” to open the Chrome developer tools. Once the dev tools are open, switch to the “Event Listeners” tab and you will see all the event listeners bound to the element.
You can add many event handlers to one element. You can add many event handlers of the same type to one element, i.e two "click" events. You can add event listeners to any DOM object not only HTML elements. i.e the window object.
Open Google Chrome and press F12 to open Dev Tools. Go to Event Listener Breakpoints, on the right: Click on the events and interact with the target element.
In jQuery before 1.8, try using $("#element").data("events")
EDIT:
There is also jQuery extension: listHandlers
When debugging, if you want to just see if there's an event, I recommend using Visual Event or the Elements" section of Chrome's Developer Tools: select an element and look for "Event Listeners on the bottom right.
In your code, if you are using jQuery before version 1.8, you can use:
$(selector).data("events")
to get the events. As of version 1.8, this is discontinued (see this bug ticket). You can use:
$._data(element, "events")
but this is not recommended since it is an internal jQuery structure, and could change in future releases.
This question has some answers which may be useful, but none of them are particularly elegant in the same way that $(selector).data("events")
was.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With