Jump to content

element.getHandlers()


10 weber
 Share

Recommended Posts

Is there a way to get the handlers of an element? For example, say we have executed window.addEventListener("click",...); and we want to get it's handler. If it had been added with window.onclick = ... it would have been easy, but what do we do in this case?
this information are available in the event object so in you example event.type will be click and event.target will be window here is a link you can check all event propertieshttp://www.javascriptkit.com/domref/domevent.shtml
Link to comment
Share on other sites

If I understand the question, you are looking for a property or method belonging to a page element that will return a list of all eventListeners that have been attached to it.So far as I know, this does not exist. And even if it did, you would still have IE issues to worry about. A strange oversight, and I would be thrilled if someone popped up and showed me I'm wrong. OTOH, I've done the same Google search you probably have and turned up nothing.One possibility is to attach a custom array to your page element (this is allowed) and simply push appropriate information onto the array every time you add a listener. Since (I hope) you are using a custom function to addEventListener for Standards-compliant browsers and addEvent for IE, you would really just need to add a few lines of code to facilitate such a thing.The actual array would most likely be an array of objects, so that each object member would hold the same values that you passed to your add-listener function. Something like:

if (!element.listeners) {   element.listeners = [];}element.listeners.push( {evt: myEvent, func: myFunction, capt: myCapture} );// access the first object like so:var myListener = element.listeners[0];// and members like so:myListener.evt;myListener.func;myListener.capt;

Note. I'm making this up off the top of my head. I'm sure there are other ways to do it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...