Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Compatibility - attachEvent vs addEventListener vs other?

    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?
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Surrey, UK
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

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