Friday, September 26th, 2008

The cross browser addEvent resurfaces

Category: JavaScript, Library

Stephen Stchur has written great posts in the past about cross browser events, and has revisited the topic with The Ultimate addEvent function article.

You get to use the function a la:


  1. var myDiv = document.getElementById('myDiv');
  2. xb.addEvent(myDiv, 'click', function(e) {
  3.    alert('The this keywords works (even in IE!): ' +;
  4. });

and he has some nice commentary:

So some of you may be wondering: “Why another addEvent function. Haven’t we been through this?” We have, but I think you’ll find that this version does more than any other addEvent function you’ve seen. For example:

  • Works in all browsers that matter
  • Ensures one event wire up for any given element/event/handler combination (this is mostly for IE)
  • Forces IE to honor the this keyword from within event handler functions
  • Normalizes the wire up mechanism in all browsers (no need to include the “on” prefix for IE)
  • Forces IE to recognize the following properties/methods on event objects: .stopPropagation(), .preventDefault(), .target, .relatedTarget
  • Enhances Non-IE browsers to support mouseenter and mouseleave events
  • Provides an extension mechanism so developers can write their own custom events that plug right in (‘mousewheel’ or ‘DOMContentReady’ for example)

Posted by Dion Almaer at 8:24 am

3.3 rating from 29 votes


Comments feed TrackBack URI

I can’t see that it does more than MochiKit.Signals: ?

Comment by Fredrik — September 26, 2008

@Frederic: yes but it is a standalone lib… I´ll definitely try it.

Comment by FrankThuerigen — September 26, 2008

This lib has some really cool concepts, among other things the “mouseenter” ripoff from MooTools and also the engine of his effect library is pretty cool, though…
The code is copyright Microsoft, it’s being used in Live Maps and it has ***NO EXPLICIT LICENSE***!!!!
At LEAST not before it has an explicit license!
The stuff it says now is; “The Gimme source code is free for the taking. Grab a copy, and hack it up to suite your needs (though you might not need to as Gimme has an extensibility model built right in). Even use the source as a jumping off point to start a project of your own!”
Sorry, that’s not good enough for my lawyers…. :(
At least until he specifically choses an explicit license this might be a potential mindfield for users… :(
Other than that; Great work Stchur :)
But *please* give us a license to obey by…. :(

Comment by ThomasHansen — September 26, 2008

Wow revolutionary, oh…wait…Mootools has had this for ages and ages and ages… probably other libs too.

Comment by csuwldcat — September 26, 2008


Thanks for your comments. I appreciate the feedback.

I assure you that the mouseenter/mouseleave code is no ripoff of MooTools. I know this because I have never used MooTools, nor looked at its source. I am not familiar with it at all.

The license for Gimme is (Ms-PL) and can be found here:

The code referred to in on is similar to what is found on Gimme, but it is just a code snippet from my blog (and a fusion of two previous articles I wrote). I apologize for failing to include the license initially. Like Gimme, it should be (Ms-PL). I will update it accordingly.

Comment by sstchur — September 26, 2008

@Stephen – about license
Great :)
Though something more “middle of the road OSI” would be better, still Ms-PL is better than “grab the code”…
@Stephen – about the rest
Sorry if I made you believe you “ripped” MooTools, that was not my intention…
I didn’t either believe you did, but MooTools are the ones currently most eager to “market” their mouseenter/mouseleave events…
Still great work, and far easier to dissect and understand your code than MooTools due to shear size, so I’ll probably end up studying your mouseenter/leave events quite extensively the next couple of days…

Comment by ThomasHansen — September 26, 2008


Sorry if I misinterpreted your MooTools comment. Regarding the license, I don’t have too much choice on it. It was important to me to be able to release the source code, but we also wanted to use it in Live Maps. The Ms-PL license was the only one that would allow it.

Thus, outside developers can view and learn from the code, modify it, create spin offs, etc… but I cannot accept user contributions.

This is another reason that I felt it important to point out that there is never any intentional ripoff code in Gimme. For two reasons really: 1) I want to honestly be able to say the work is original, but more importantly 2) I’m not allowed to to copy any outside work.

I’ve made it a point throughout the entire Gimme development never to view the source of any other Javascript libraries.

In any case, I appreciate the feedback. Certainly feel free to send me your suggestions. I’m more than happy to help!

Comment by sstchur — September 26, 2008

Leave a comment

You must be logged in to post a comment.