Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding DIVs 2

Status
Not open for further replies.

welshone

Programmer
Jul 30, 2001
414
GB
Hello,
How can I hide one div and display another with a click of a link ?

is that possible?
 
Here is a very simple example using Javascript. The javascript forum can give you more ways of doing so.

<div id=&quot;one&quot; style=&quot;visibility:hidden;&quot;>I'm hidden for now</div>
<div id=&quot;two&quot; style=&quot;visibility:visible;&quot;>I'm visible for now</div>

<a href=&quot;#gonowhere&quot; onclick=&quot;document.getElementById('one').style.visibility = 'visible';document.getElementById('two').style.visibility = 'hidden';&quot;>Click me! :)</a> Gary Haran
 
In case you want to change the visibility in the backwards I added some code in xutopia's example.
Click two time on the link !

<html>
<head>

<script language=&quot;javascript&quot;>

function HideUnhide()
{
div1 = document.getElementById('one');
div2 = document.getElementById('two');

if (div1.style.visibility == 'hidden')
{
div1.style.visibility = 'visible';
div2.style.visibility = 'hidden';
}
else
{
div1.style.visibility = 'hidden';
div2.style.visibility = 'visible';
}
}
</script>

</head>
<body>

<div id=&quot;one&quot; style=&quot;visibility:hidden;&quot;>I'm visible for now (div1)</div>
<div id=&quot;two&quot; style=&quot;visibility:visible;&quot;>I'm visible for now (div2)</div>

<a href=&quot;#gonowhere&quot; onclick=&quot;HideUnhide()&quot;>Click me! :)</a>

</body>
</html>

Hope this helps,
Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top