javascript – Get event listeners attached to node using addEventListener-ThrowExceptions

Exception or error:

I have already looked at these questions:

however none of them answers how to get a list of event listeners attached to a node using addEventListener, without modifying the addEventListener prototype before the event listeners are created.

VisualEvent doesn’t display all event listener (iphone specific ones) and I want to do this (somewhat) programmatically.

How to solve:

Chrome DevTools, Safari Inspector and Firebug support getEventListeners(node).



You can’t.

The only way to get a list of all event listeners attached to a node is to intercept the listener attachment call.

DOM4 addEventListener


Append an event listener to the associated list of event listeners with type set to type, listener set to listener, and capture set to capture, unless there already is an event listener in that list with the same type, listener, and capture.

Meaning that an event listener is added to the “list of event listeners”. That’s all. There is no notion of what this list should be nor how you should access it.


Since there is no native way to do this ,Here is less intrusive solution i found (dont add any ‘old’ prototype methods):

var ListenerTracker=new function(){
    var is_active=false;
    // listener tracking datas
    var _elements_  =[];
    var _listeners_ =[];
        if(!is_active){//avoid duplicate call
    // register individual element an returns its corresponding listeners
    var register_element=function(element){
            // NB : split by useCapture to make listener easier to find when removing
            var elt_listeners=[{/*useCapture=false*/},{/*useCapture=true*/}];
        return _listeners_[_elements_.indexOf(element)];
    var intercep_events_listeners = function(){
        // backup overrided methods
        var _super_={
            "addEventListener"      : HTMLElement.prototype.addEventListener,
            "removeEventListener"   : HTMLElement.prototype.removeEventListener

        Element.prototype["addEventListener"]=function(type, listener, useCapture){
            var listeners=register_element(this);
            // add event before to avoid registering if an error is thrown
            // adapt to 'elt_listeners' index

        Element.prototype["removeEventListener"]=function(type, listener, useCapture){
            var listeners=register_element(this);
            // add event before to avoid registering if an error is thrown
            // adapt to 'elt_listeners' index
            var lid = listeners[useCapture][type].indexOf(listener);
            var listeners=register_element(this);
            // convert to listener datas list
            var result=[];
            for(var useCapture=0,list;list=listeners[useCapture];useCapture++){
                if(typeof(type)=="string"){// filtered by type
                        for(var id in list[type]){
                }else{// all
                    for(var _type in list){
                        for(var id in list[_type]){
            return result;


You can obtain all jQuery events using $._data($(‘[selector]’)[0],’events’); change [selector] to what you need.

There is a plugin that gather all events attached by jQuery called eventsReport.

Also i write my own plugin that do this with better formatting.

But anyway it seems we can’t gather events added by addEventListener method. May be we can wrap addEventListener call to store events added after our wrap call.

It seems the best way to see events added to an element with dev tools.

But you will not see delegated events there. So there we need jQuery eventsReport.

UPDATE: NOW We CAN see events added by addEventListener method SEE RIGHT ANSWER TO THIS QUESTION.


I can’t find a way to do this with code, but in stock Firefox 64, events are listed next to each HTML entity in the Developer Tools Inspector as noted on MDN’s Examine Event Listeners page and as demonstrated in this image:

screen shot of FF Inspector

Leave a Reply

Your email address will not be published. Required fields are marked *