michaelp0730
1/19/2015 - 6:28 PM

John Resig's Event Listeners


	if (document.addEventListener) {
          this.addEvent = function (elem, type, fn) {
               elem.addEventListener(type, fn, false);
               return fn;
          };


          this.removeEvent = function (elem, type, fn) {
               elem.removeEventListener(type, fn, false);
          };
     } else if (document.attachEvent) { // legacy IE
          this.addEvent = function (elem, type, fn) {
               var bound = function () {
                    return fn. apply(elem, arguments);
               };
               elem.attachEvent(“on” + type, bound);
               return bound;
          };


          this.removeEvent = function (elem, type, fn) {
               elem.detachEvent(“on” + type, fn);
          };
     }