Click to See Complete Forum and Search --> : class changing


benb7760
11-06-2004, 05:59 AM
I have <td></td> tags, with text inbetween. I want to know the syntax for changinf the class of the <td> tags, I know it will be 'onmouseclick', but how can I make it so it toggles between two class'. eg. cliked, change class to 'hi', then, when clicked again, change class to 'ok'. etc

Fang
11-06-2004, 06:29 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>change class</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
<!--
function changeClass(obj) {
obj.className=(obj.className=="on")? "off" :"on";
}
//-->
</script>

<style type="text/css">
<!--
.on {color:red;}
.off {color:green;}
-->
</style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" summary="">
<tr><td onclick="changeClass(this);" class="off">xxxx</td></tr>
</table>
</body>
</html>