SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Mar 13, 2007, 05:00 #1
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
-
Mar 13, 2007, 06:24 #2
- Join Date
- Sep 2006
- Posts
- 731
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Mar 13, 2007, 08:42 #3
- 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