Click to See Complete Forum and Search --> : How can I change the class name in Netscape


MagnoliaKobus
12-31-2003, 09:52 PM
I'd like to change the class name dynamically.
Like that,
myIdName.className = "request";
It could work well in IE but couldn't run in Netscape.
Please give me some suggestions concerned with Netscape compatible script .

fredmv
12-31-2003, 09:56 PM
This works fine for me in Mozilla:<!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" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
<style type="text/css">
/*<![CDATA[*/
.class1 {
color: #f00;
}

.class2 {
color: #00f;
}
/*]]>*/
</style>
</head>
<body>
<div onmouseover="className='class1';" onmouseout="className='class2';">
foo
</div>
</body>
</html>

MagnoliaKobus
12-31-2003, 10:38 PM
I used the following code. If so, how could I change ?
<html>
<head>
<title>Script Testing</title>
<style type="text/css">
.normtext
{
BACKGROUND-COLOR: #006699
}
.selecttext
{
BACKGROUND-COLOR: #f5deb3
}
</style>
<script language=javascript>
function changeClass(){
var src = window.event.srcElement;
if (src.parentElement.id == "myId"){
if(myId.className == "normtext")
myId.className = "selecttext";
else
myId.className = "normtext";
}
}
</script>
</head>
<body>
<form name=frm>
<table border=0 cellspacing=0 cellpadding=0 width=50% align=center>
<tr id=myId class=normtext onclick=changeClass(); height="5px">&nbsp;<td></td></tr>
</tabel>
</form>
</body>
</html>

ray326
01-01-2004, 02:38 PM
It's a lot easier if you just pass the element to the handler:

function changeClass(src){
if (src.id == "myId"){
if(src.className == "normtext")
src.className = "selecttext";
else
src.className = "normtext";
}

And

<tr id="myId" class="normtext" onclick="changeClass(this);" height="5px">

MagnoliaKobus
01-02-2004, 12:09 AM
"myId.className"
It doesn't work in Netscape.

ray326
01-02-2004, 09:22 AM
Originally posted by MagnoliaKobus
"myId.className"
It doesn't work in Netscape.
Did you actually read what fredmv and I posted?

fredmv
01-02-2004, 03:44 PM
Originally posted by ray326
Did you actually read what fredmv and I posted? I was just thinking the same thing. :D