dismayldream
Programmer
I'm trying to bind an event argument to an anonymous function that encapsulates a call to class method that requires access to the event object. The problem is if I place the word 'event' or 'e' in the anonymous function that wraps my class method call - the JS just errors citing e/event as undefined. This doesn't happen in IE. If I embed the class method call directly in the XHTML element's onmouseover/onmousemove events (E.g. <span onmouseover="clueTip.showTooltip(event, clueTip);">Blah</span>), I can pass the reserved word 'event' without incidence. I'm sure it's something to do with scope and my misunderstanding of how JavaScript is working with event - any clarification would be great. I've outlined a snippet of the code below:
Code:
// Occurs in body.onload()
elsToTip = document.getElementsByTagName("span");
if(elsToTip[y].addEventListener)
{
// for Firefox (Javascript errors citing 'event' as undefined)
elsToTip[y].addEventListener("mousemove",function(){ clueTip.showTooltip(event, clueTip);}, false);
elsToTip[y].addEventListener("mouseover",function(){ clueTip.showTooltip(event, clueTip);}, false);
elsToTip[y].addEventListener("mouseout",function(){clueTip.hideTooltip(event, this, clueTip);}, false);
}
else if(elsToTip[y].attachEvent)
{
// for IE (This works - event is passed in)
elsToTip[y].attachEvent("onmousemove",function(){clueTip.showTooltip(event, clueTip);});
elsToTip[y].attachEvent("onmouseover",function(){clueTip.showTooltip(event, clueTip);});
elsToTip[y].attachEvent("onmouseout",function(){clueTip.hideTooltip(event, this, clueTip);});
}
(...)