It can be done in two ways. The difference between the two methods is obvious: one of them(visibility) doesn't change the page layout while the other(display) does.
<html>
<head>
<script>
function hide()
{
var elem = document.getElementById('myP');
elem.style.display = 'none';
}
function show()
{
var elem = document.getElementById('myP');
elem.style.display = '';
}
function hide2()
{
var elem = document.getElementById('myP2');
elem.style.visibility = 'hidden';
}
function show2()
{
var elem = document.getElementById('myP2');
elem.style.visibility = 'visible';
}
</script>
</head>
<body>
<form>
<h2 align="center">Using the display property of CSS</h2>
<p id="myP">Here is some text which I want to hide</p>
<input type="button" onclick="hide();" value="Hide" />
<input type="button" onclick="show();" value="Show" />
<h2 align="center">Using the visibility property of CSS</h2>
<p id="myP2">Here is some text which I want to hide</p>
<input type="button" onclick="hide2();" value="Hide" />
<input type="button" onclick="show2();" value="Show" />
</form>
</body>
</html> ~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734