Created
October 15, 2009 18:03
-
-
Save alanedwardes/211143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// By Alan Edwardes - http://alanedwardes.com/contact | |
// Licensed under The GNU General Public License (GPL) | |
// ------------------------------------------------------------- | |
// A simple events wrapper function for adding events that works | |
// cross browser, and allows you to use the first parameter of | |
// the callback function as a reference to the object that the | |
// event was fired from, which replaces IE's lack of support | |
// for the "this" variable. | |
// | |
// Ex. Usage: | |
// ------------------------------------------------------------------------ | |
// AddEvent(document.GetElementById('SomeElement'),'mousedown',MyCallback); | |
// | |
// function MyCallback(Element){ | |
// alert('This is the content of my element: ' + Element.innerHTML); | |
// } | |
function AddEvent(Element,Event,Callback){ | |
if(window.addEventListener){ | |
Element.addEventListener(Event,function(){ | |
Callback(Element); | |
},false); | |
}else if(window.attachEvent){ | |
Element.attachEvent('on'+Event,function(){ | |
Callback(Element); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment