PDA

View Full Version : Changing class help...


Girvo
11-14-2005, 04:33 AM
Hi there.
Well'p, I am just experimenting here, but I have struck a snag. I wish to make it so that when a user clicks on the 'hide' link, it will hide another part of the page. But, it doesn't seem to be working:


<head>
<title>A cool xHtml site</title>
<style type="text/css">
<!--
.visible
{
display:true;
}

.hide
{
display:false;
}
//-->
</style>

<body>
<p>
<a href="#" onclick="test.class='hide';" id='something'>Hide</a>
<div id="test" class="visible">Hi there! Test!</div>
</p>
</body>


Thanks for your help.
-Girvo

birdbrain
11-14-2005, 05:20 AM
Hi Girvo,

try it like this, I have highlighted the amendments...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A cool xHtml site</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
<!--
.visible {
display:block;
}
.hide {
display:none;
}
-->
</style>

</head>
<body>

<div>
<a href="#" onclick="document.getElementById('test').className='hide';return false" id='something'>Hide</a>
<p id="test" class="visible">Hi there! Test!</p>
</div>

</body>
</html>

Girvo
11-14-2005, 06:24 AM
That works really well, thanks! I was just wondering, is it possible to check whether it is hidden, and if so, make it visible, or vice-versa? How would I go about this?

birdbrain
11-14-2005, 06:38 AM
Hi Girvo,

do you mean like this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A cool xHtml site</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
<!--
.visible {
display:block;
}
.hide {
display:none;
}
-->
</style>

<script type="text/javascript">
<!--
function hideShow() {

var obj=document.getElementById('test');

if(obj.className=='hide') {
obj.className='visible';
}
else {
obj.className='hide';
}
}
//-->
</script>

</head>
<body>

<div>
<a href="#" onclick="hideShow();return false" id='something'>Hide/Show</a>
<p id="test" class="visible">Hi there! Test!</p>
</div>

</body>
</html>

Girvo
11-15-2005, 12:54 AM
Yep :D thanks for that.