Skip to content

Instantly share code, notes, and snippets.

@olooney
Created June 15, 2011 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olooney/1027365 to your computer and use it in GitHub Desktop.
Save olooney/1027365 to your computer and use it in GitHub Desktop.
cross-browser event listeners
// observable is a DOM node, document, window, etc.
// eventName is the string event name, say "load" or "click"
// handler is the callback function.
function addEventListener(observable, eventName, handler) {
if ( observable.addEventListener ) {
observable.addEventListener(eventName, handler, false);
} else if ( observable.attachEvent ) {
observable.attachEvent("on" + eventName, handler);
} else {
// error handling?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment