SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Quark's Avatar
    Join Date
    Sep 2006
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Test whether element has an attachEvent

    Hi,
    I'm looking for a way to test whether an html element already has an event attached to it. In ie6 I add an event to an element with (must use attachEvent, can not use element.onclick = f; ):

    element.attachEvent("onclick", eventHandler(element, "click"));

    How can I test whether an element has this particulair event already attached to it? So something like:

    if ( element.hasAttachedEvent("onclick", eventHandler(element, "click")); )
    {
    }

    hasAttachedEvent does not exist, how do I do this? Thx

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Quark View Post
    Hi,
    I'm looking for a way to test whether an html element already has an event attached to it. In ie6 I add an event to an element with (must use attachEvent, can not use element.onclick = f; ):

    element.attachEvent("onclick", eventHandler(element, "click"));

    How can I test whether an element has this particulair event already attached to it? So something like:

    if ( element.hasAttachedEvent("onclick", eventHandler(element, "click")); )
    {
    }

    hasAttachedEvent does not exist, how do I do this? Thx
    if ( typeof element.onclick == 'function' )
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't find handlers set with attachEvent or addEventListener by reading the event type property of the element. (element.onclick)

    In fact, the only way I resolved this was to maintain an object that shadows
    'active' elements with an event list object, and update it with a central addEvent function that is always used to add or remove (detach) events or listeners. It is handy for developing scripts and error checking, but a lot of overhead for general web page viewing.


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
  •