Jump to content


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...