SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    List of registered events

    Hi there,

    I have two questions to ask.

    1. How do I check which events are registered with a specific element.
    2. How do I check which event handler is registered with a specific event on an element.

    Basically, what I'm trying to do is allow the user to add events on an element. This part I was able to do. But now, I would like to give them an option to be able to remove events. I know that I will have to use removeEventListener and detachEvent for this. But when the user tries to remove an event, I would like to check two things:

    i) if that event is registered with this element

    ii) if it is, then check if the provided function / event handler was registered with the given event

    Please let me know if there's a better way to achieve this. Thanks so much in advance.
    With Regards
    Pman
    http://www.pmansLab.com

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could wait for html5, which will log event registration, but chances are IE won't support it.

    I use a central addEvent function for all eventListeners (and attach events)that creates and updates a shadow object with an array of handlers for each element type set.

    calling Shadow[element.id].eventList.click returns an array of handlers for the element's click event, and so on. Removing a handler removes its item in the array, adding a duplicate is ignored.

    It is most useful for error tracking and testing-

    if you always run detachEvent on the same arguments you then attachEvent with, you will prevent IE from adding duplicate handlers for the same element and event type. The dom event browsers will ignore duplicates.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •