Wednesday 11 September 2019

javascript - 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.


Answer



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')




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...