[thelist] IE > attachEvent not triggering function
Paul Bennett
Paul.Bennett at wcc.govt.nz
Wed Jan 25 16:24:45 CST 2006
Hi all,
I'm trying to remove js code from our pages and put it into it's own files where it belongs but am struggling with IE's attachEvent functions.
Basically, I'm getting feedback (via alerts) that the event is being attached successfully, but the function to fire when the page element is moused-over isn't being called.
Code below is working fine in FF / Opera, but not in IE (no JS errors in IE).
(Unable to post a link, sorry)
-----------------------
function setHandlers(){
theLink = document.getElementById('returnLink');
if( theLink.addEventListener ) {
// attach listeners for stds compliant brwsrs
theLink.addEventListener('mouseover',imgSwap,false);
theLink.addEventListener("mouseout", MM_swapImgRestore, false);
}
else if ( theLink.attachEvent ){
// IE (bless it's heart)
checkAttach = theLink.attachEvent('mouseover', imgSwap);
// check if this event attached successfully
if(checkAttach){
alert('Event attached');
}
else{
alert('Event attach failed');
}
theLink.attachEvent('mouseout',MM_swapImgRestore);
}
else{
// older browsers
theLink.onmouseover = imgSwap();
theLink.onmouseout = MM_swapImgRestore();
}
}
/* wrapper function for mouseover event */
function imgSwap(){
alert('triggered');
MM_swapImage('returntolist1','','/images/functionbuttons/returntolistrollover.gif',1);
}
-----------------------
Thanks in advance for any pointers,
Paul
More information about the thelist
mailing list