Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 256
Alberto De Caro Avatar asked Nov 12 '12 23:11

Alberto De Caro


1 Answers

No, it is not possible with DOM methods.

However, some libraries store all handlers they bind in element-associated data structures to enable methods like unbindAll.

like image 189
Bergi Avatar answered Oct 17 '22 06:10

Bergi