How to check if any JavaScript event listeners/handlers attached to an element/document?
dom-events, javascript, jquery
Solution
Without jQuery:
if the listeners were added using `elem.addEventListener()` method, it is not easy to list these listeners. You can override the `EventTarget.addEventListener()` method by wrapping it with your own. Then you will have the information, what listeners were registered.
var f = EventTarget.prototype.addEventListener; // store original
EventTarget.prototype.addEventListener = function(type, fn, capture) {
this.f = f;
this.f(type, fn, capture); // call original method
alert('Added Event Listener: on' + type);
}
Working example you can find at http://jsfiddle.net/tomas1000r/RDW7F/
Problem
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?