I've read most of the relevant articles in quirksmode.org but still I'm not sure about this one:
Making my app compatible with IE8 (fun fun fun) I encounter this issue when trying to set an onclick event to a link:
function myClickHandler(event)
{
alert(event);
}
var link = document.getElementById("myLink");
link.onclick = myClickHandler; //first option
As opposed to:
function myClickHandler(event)
{
alert(event);
}
var link = document.getElementById("myLink");
link.onclick = function() {
myClickHandler(event); //second option
}
Using the first option, myClickHandler alerts undefined
. Using the second option alerts [object Event]
which makes me believe that the event object isn't passed by the first option to the handler. Why is this so on IE8?
Note: Don't want to use attachEvent as I want to override a single listener during execution and onclick
seems to fit here fine.