I have experienced this same problem recently. I have a JS function I wrote and have used for years that, on page load, dynamically attaches hover functions (changing the image src) to the onmouseover and onmouseout events of certain images. (A much cleaner way than littering your HTML with messy, verbose inline onmouseover/onmouseout events.) As far as I can recall, it's always worked in all browsers...until today.
For some reason, in IE7, a set of images weren't working with this function. No errors; it just seemed like the onmouseover event wasn't firing at all.
I had seen another thread that talked about a problem in IE where the EventListener hadn't worked for mouseover, and so the poster had found that using the older "onmouseover" method was the only way to make it work in IE.
I just tried this method, and sure enough, it fixed the problem. Strange.
Now I think that probably the reason that poster had a problem is the discrepancy you note between the appropriate methods for IE vs. <Rest of World>.
Here's the function I was using to attach the hover functions to the events (from
dustindiaz.com ):
[HTML]
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
}
else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
}
else {
elm['on' + evType] = fn;
}
}[/HTML]
Then I tried replacing it with this (supposedly more robust) addEvent function (also from
dustindiaz.com):
[HTML]function addEvent( obj, type, fn ) {
if (obj.addEventListener) {
obj.addEventListener( type, fn, false );
}
else 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["on"+type] = obj["e"+type+fn];
}
}[/HTML]
For some reason, that also fixed the problem. Not sure why that worked better than the other addEvent(), but it did.
So this seems to confirm that attaching events in IE is not all that simple, straightforward and reliable.
Cameron