Wednesday, 9 November 2016

Javascript: how to get a list of the event handlers bound to an event


Possible Duplicate:
How to find event listeners on a DOM node?






Given an element, let's say a div, is it possible to obtain a list of the handlers bound to a specific event fired by the element?



/* pseudo code: click on a div handlers? */
document.getElementById('myDiv').getHandlers('click');


Edit



Ok, here's some more details. I want to bind a click handler to a div, unless another handler is already bound to the div. What I have in mind is the following:



/* pseudo code: click on a div handlers? */
if(!document.getElementById('myDiv').getHandlers('click'))
document.getElementById('myDiv').addEventListener('click', myEventhandler);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...