PDA

View Full Version : Compatibility - attachEvent vs addEventListener vs other?


beetle
03-17-2003, 03:50 PM
Hey all

Working on something but I'm really busy, so I'll let this answer come to me, if you guy have it. As I understand it so far:

element.attachEvent()
IE 5+ for PC

element.addEventListener()
Gecko, KHTML

element.event
NS3+, IE4+, dunno about opera or others

Since I'm only concerned with attaching a single event and don't care about bubbling/capturing, am I best off not using the old style of event registering to assure maxium compatibility?

liorean
03-17-2003, 09:38 PM
Well, elm.onevent works. I can't say the IE proprietary or even W3C version really does - not in that wide spectrum of browsers. So long as you don't need to handle bubbling/capturing, the DOM0 model is the only way a pragmatical person would do it.

ahosang
03-20-2003, 01:21 PM
I agree with liorean. Yes, you could branch and do newer DOM techniques, but i find if you just want simple event attach, just use element.onclick=myfunc;
as you said. Also, this seems to give least problems when attaching event handlers to dynamically created elements(document.createElement("ELEMENTTYPE"). Works for more platforms/browser versions etc.