views:

1357

answers:

3

why IE have so many problem ????? it waste lots of time.....

Updated code :

function getElements()
  {
  var x=document.getElementsByTagName("option");

var el = document.getElementById('selectDept');
el.onmouseover = function( myevent ) {
   // event = event || window.event.srcElement;
if(myevent && myevent.target){
    if ( myevent.target.tagName.toLowerCase() == 'option' ) {
        alert(myevent.target.innerHTML);
    }
}
else if(window.event)
{
   if ( window.event.srcElement.tagName.toLowerCase() != 'select' ) {
        alert('s');
    }

}
};

but still not work in IE.

+1  A: 

Can't you still set a mouseover event handler on the whole select, and target the event property if the target is an option element, do X action?

var el = document.getElementById('foo')
el.onmouseover = function( event ) {
    event = event || window.event;
    var target = event.target ? event.target : event.srcElement;
    if ( target.nodeName.toLowerCase() === 'option' ) {
        alert('option');
    }
}

Updated code:

http://jsbin.com/olusi

meder
do you have sample code ? I tried , but not work
MemoryLeak
updated with pseudo code example, I just typed it in the post I didn't actually test this out. You may need to account for bubbling with stopPropagation and such though, let me know how it goes.
meder
I think you need the event.srcElement in IE to get which element triggered the event. http://msdn.microsoft.com/en-us/library/ms534638%28VS.85%29.aspx
scunliffe
i was looking that up because I forgot to account for the target, ty though.
meder
but still not work ...
MemoryLeak
edit your original post with what you have tried thus far.
meder
I updated with a live example... let me know if it doesn't work in IE.
meder
event = event || window.event;what is this used for ?
MemoryLeak
http://jsbin.com/olusiit works in firefox, but not in IE8
MemoryLeak
+4  A: 

IE does not support events on the option element. You can try as @meder says to add a handler on the parent select and then inspect the event to see which option was moused over.

PS these were known bugs in IE6 (and reported in IE7 and IE8 beta testing - and rejected for fixing to date) :-(

Maybe IE9 will support them?

scunliffe
A: 

JSBin your code is not working in IE 8 :-(

manu