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
You don't have to use jQuery, but you could try John Resig's popular addEvent funciton.
addevent(elem, "click",clickevent);
function addEvent ( obj, type, fn ) {
if ( obj.attachEvent ) {
obj["e"+type+fn] = fn;
obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
obj.attachEvent( "on"+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
}
There are more to be considered to'properly' bind an event on HTML tags in pure javascript.
http://www.pagecolumn.com/javascript/bind_event_in_js_object.htm