uk1900
asked on
hide/show nested divs
hi,
how can I hide and show nested divs in <div id=main> ?
how can I hide and show nested divs in <div id=main> ?
<div id=main>
<div>...</div>
<div>...</div>
<div>...</div>
</div>
you must set "display" attribute. for example use a function like this:
<script type="text/javascript" language="javascript">
function SwitchVisibility(eID)
{
if (document.getElementById(e ID).style. display==" none")
document.getElementById(eI D).style.d isplay="";
else
document.getElementById(eI D).style.d isplay="no ne";
}
</script>
and for change the display mode for any element you must call the function with id's of your element.
for example :
<div id="MainDiv">
<div id="Div1" style="display:none">
11111111111111111111111111 1111111111 1111111111 1111111111 </br>
</div>
<div id="Div2" style="display:none">
22222222222222222222222222 2222222222 2222222222 2222222222 </br>
</div>
<div id="Div3" style="display:none">
33333333333333333333333333 3333333333 3333333333 3333333333 </br>
</div>
</div>
<span onclick="SwitchVisibility( 'Div2');"> click here</span>
<script type="text/javascript" language="javascript">
function SwitchVisibility(eID)
{
if (document.getElementById(e
document.getElementById(eI
else
document.getElementById(eI
}
</script>
and for change the display mode for any element you must call the function with id's of your element.
for example :
<div id="MainDiv">
<div id="Div1" style="display:none">
11111111111111111111111111
</div>
<div id="Div2" style="display:none">
22222222222222222222222222
</div>
<div id="Div3" style="display:none">
33333333333333333333333333
</div>
</div>
<span onclick="SwitchVisibility(
ASKER
thx hielo,
this will hide the main div too, is it possible to show/hide only the nested divs?
this will hide the main div too, is it possible to show/hide only the nested divs?
<div id='main' style='display:none'>
<span onclick="ShowHideNested('main')">Toggle Main</span>
<div>...a</div>
<div>...b</div>
<div>...c</div>
</div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you for your help
You are welcome!
Open in new window