2

There seem to be endless pages of writing and comment threads about addEvent implementations in Javascript, going back many years.

What should I be using today, in currentTime.getFullYear(), for the most versatile, simple cross-browser addEvent implementation? What is the best practice? Is there a standard anywhere on the horizon?

Is google's base2 library a panacea for this problem?

Background:
Crossbrowser DOM Scripting: Event Handlers
addEvent() considered harmful
addEvent() recoding contest
Flexible Javascript Events
A problem with John Resig's addEvent
addEvent() – My Solution

jordanpg
  • 6,386
  • 4
  • 46
  • 70

1 Answers1

0

IE9+ all support window.addEventListener see https://developer.mozilla.org/en-US/docs/DOM/element.addEventListener

To support everyone else you have to do some fanciness to support both it and window.attachEvent.

See: https://stackoverflow.com/a/6925427/496735

Community
  • 1
  • 1
Jamund Ferguson
  • 16,721
  • 3
  • 42
  • 50