Search code examples
jquerydomlistenerdom-events

How to print out or iterate for each event listener attached to element?


How would one print out to console, or iterate for each event listener that is attached to specific DOM element?

I have tried using .eventListenerList but I am getting undefined.


Solution

  • Try,

    $('#elem').data('events')
    

    update:

    .data(“events”): jQuery stores its event-related data in a data object named (wait for it) events on each element. This is an internal data structure so in 1.8 this will be removed from the user data name space so it won’t conflict with items of the same name. jQuery’s event data can still be accessed via jQuery._data(element, "events") but be aware that this is an internal data structure that is undocumented and should not be modified.

    So according to the data from the doc, if you use jquery version > 1.8 then you should follow this method to retrieve informations

    $._data($('elem')[0],'events')
    

    DEMO