hiding and showing parts of a page using <DIV>


i'm designing a webpage with a lot of info on it and i want to hide most of it until somebody clicks a link, then it should expand en show the details


<a href=# onClick="ShowDiv(1);">link 1</a>
<div name=x1 class=mydivclass>info</div>
<a href=# onClick="ShowDiv(2);">link 2</a>
<div name=x2 class=mydivclass>info</div>
<a href=# onClick="ShowDiv(3);">link 3</a>
<div name=x3 class=mydivclass>info</div>

the info in the divs is initially hidden using document.mydivclass.style.display="none"

how do i
-refer to one specific div, how can i turn a variable into an object (ie divname="SuchAndSo" and then i want to set properties in the way of document.divname.property etc)

- make this div visible
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi there:

You must use this code:

<script LANGUAGE="javascript">
var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;
function show(id) {
  if (ns) document.layers[id].visibility = "show"
      else if (ie) document.all[id].style.visibility = "visible"
function hide(id) {
  if (ns) document.layers[id].visibility = "hide"
      else if (ie) document.all[id].style.visibility = "hidden"

and declare ths divs this way:

<style TYPE="text/css">
#menu1layerDIV {position:absolute; left:1; top:140; visibility:hidden;}-->
<div id="menu0layerDIV">

If you want to hide it just do this:
and if you want to show it:

Now if you wanto to convert a variable into an object just do this:

eval("document." + divname + ".property = fooo")


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
heitAuthor Commented:
xabi, code works fine, thanx!

i've increased the points because i have an additional question:

i can't use the absolute positioning because i don't know how much text should be above the div ... what i would like to do is design it in a way that it really pops up between the lines, so that first i've got a lot of text, then i press a link and then the text separates and a div show in between. Now i use relative divs, but when it is invisible it still takes the place between the lines, only the divtext is hidden.

Do you know how to solve this?

i use ie 4.0
Here goes the IE code:

--------- 8< -------- 8< ----
<script LANGUAGE="javascript">
function clikker(a) {
  if (a.style.display =='') a.style.display = 'none'
  else a.style.display=''

<body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
<a href="javascript:clikker(menu)">click</a><br>
end of text--------------<br>
<div <div ID="menu" STYLE="DISPLAY: none" >
ini ------<br>
end ----
--------- 8< ------ 8< ------


PS: Only IE
heitAuthor Commented:
great, it works just fine!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.