I know this is easily done in jQuery or any other framework, but that\'s not really the point. How do I go about \'properly\' binding a click event in pure javascript? I kno
This is a nice cross-browser method
var on = (function(){
if ("addEventListener" in window) {
return function(target, type, listener){
target.addEventListener(type, listener, false);
};
}
else {
return function(object, sEvent, fpNotify){
object.attachEvent("on" + sEvent, function(){
fpNotify(window.event);
});
};
}
}());
on(document.getElementById("myAnchor"), "click", function(){
alert(this.href);
});