...

View Full Version : Works in IE and Mozilla but not in NS, why?



S7even
06-12-2003, 08:17 AM
Can you tell me why the following works in IE, Mozilla and Opera but not in NS? I don't care about NS4, I just need it to work in NS6+


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mouse Over</title>
<script language="JavaScript" type="text/javascript">
function domouseover(e) {
e = (e) ? e : (window.event) ? window.event : ""
if (e) {
var elem = (e.target) ? e.target : e.srcElement
if (elem.className == "test" ) {
y=elem.id+'r';
document.getElementById(y).style.color = 'red';
}
}
}
function domouseout(e) {
e = (e) ? e : (window.event) ? window.event : ""
if (e) {
var elem = (e.target) ? e.target : e.srcElement
if (elem.className == "test" ) {
y=elem.id+'r';
document.getElementById(y).style.color = 'black';
}
}
}
document.onmouseover=domouseover;
document.onmouseout=domouseout;
</script>
</head>
<body>
<div id="x1r">
This should become red when you mouse over the link, but it doesn't in Netscape.
</div>
<a href="#" id="x1" class="test">Mouse over me</a>
</body>
</html>

ahosang
06-12-2003, 10:21 AM
Guessing now, because i can't test till later, but maybe:
var elem = (e.target) ? e.target : e.srcElement
might be the problem for NS6(inconsistencies between the Mozilla versions were a problem)
Try:
var elem = (e.target) ? e.currentTarget : e.srcElement
for nS6 and branch if that helped.

S7even
06-12-2003, 01:51 PM
just changing the line of
var elem = (e.target) ? e.target : e.srcElement
to
var elem = (e.target) ? e.currentTarget : e.srcElement
in the two functions didn't help :(
Actually it doesn't work in Mozilla either this way.

Should I change something more?

jkd
06-12-2003, 02:40 PM
The text node is being targeted. Use e.target.parentNode;

S7even
06-12-2003, 02:47 PM
Yes!
Now it works in NS and IE, but not in Mozilla ... how do i combine everything to make it work for all browsers?

S7even
06-13-2003, 05:13 AM
Anybody? :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum