Forum Moderators: not2easy

Message Too Old, No Replies

Change class not working in FireFox

but works in IE and Opera

         

Blackie

2:03 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Here is the simplified code, which works in Opera and IE but not FireFox:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script type=text/javascript>
function ClassChange(element,newclass) {
if (event.srcElement.className == "furtherDef") {
event.srcElement.className = "highlight";
}
else {
event.srcElement.className = "furtherDef";
}
element.className = newclass;
}
</script>
<style type=text/css>
.highlight { background-color: #ccc; }
.visible {visibility:visible;}
.hidden {visibility:hidden;}

#b1 {
position: absolute;
top:0px;
}
#b2 {
position: absolute;
top:0px;
}
</style>
</head>

<body>
<div id=b1 class=visible>
Visible
<p id="p1" class="furtherDef" onMouseOver="ClassChange(p1,'highlight')" onMouseOut="ClassChange(p1,'furtherDef')"
onClick="ClassChange(b1,'hidden');ClassChange(b2,'visible');" >Click here</p>
</div>

<div id=b2 class=hidden>
Hidden
</div>

</body>
</html>

How to tune it for FF?

dcrombie

2:05 pm on Jun 9, 2005 (gmt 0)



Try this (you need to return 'true' for a Mouseover event to be executed):

onMouseover="ClassChange(p1,'highlight'); return true;"

Blackie

2:11 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Unfortunately no luck :-(

dcrombie

2:18 pm on Jun 9, 2005 (gmt 0)



Then you need some cross-browser code for the event handling. The global variable "event" is only present in Explorer and (apparently) Opera.

Moby_Dim

2:25 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Blackie, there is a javascript console option in ff. Use it to investigate code bugs. Very useful. And you'll learn more this way. (Your problem is simple btw.)