How to hide/show a div?

  • Thread starter Miguel Dias Moura
  • Start date
M

Miguel Dias Moura

Hello,

I have an image and a div named "content" in an ASP.Net / VB web page.

I need to create something like an on/off (visible/hidden).

1. When I click the image and the div is visible, the div becomes
hidden.
2. When I click the image and the div is hidden, the div becomes
visible.

So it's only one image controlling the div visibility.

How can I do this?

Thanks,
Miguel
 
J

jasonkester

Server side or client side?

On the server, it's easy:
myControl.Visible = true;
myOtherControl.Visible = false;

On the client, it's trickier, but doable:
<script>
// Always test EVERYTHING! Script errors suck.
if (document && document.getElementById)
{
var myControl = document.getElementById("myControl");
var myOtherControl = document.getElementById("myOtherControl");

if (myControl && myOtherControl)
{
myControl.style.visibility = "visible";
myControl.style.position = "relative";

myOtherControl.style.visibility = "hidden";
myOtherControl.style.position = "absolute";
}
}
</script>

Good luck!
Jason
Expat Software Consulting Services
http://www.expatsoftware.com/
 
M

Miguel Dias Moura

Hi,

Thanks for the help.

What are the advantages and disadvantages or each approach?

Is server side code the best way?

Thanks,
Miguel
 
R

Rob Labbe \(Lowney\)

Miguel Dias Moura said:
Hi,

Thanks for the help.

What are the advantages and disadvantages or each approach?

Is server side code the best way?

It depends, server side code will required a round trip back to the server,
slowing your user experience and adding load to the server but will always
work regardless of the client.

Client side will perform better, but you have the problem of testing to
ensure your client side script works on all browsers, and the knowledge that
it won't work at all if the user has scripting turned off.


--
Rob Labbé, MCP, MCAD, MCSD, MCT
Lead Architect/Trainer
Fidelis

Blog: http://spaces.msn.com/members/roblabbe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top