Forum Moderators: open

Message Too Old, No Replies

ToggleDiv hid and show.

         

tonynoriega

3:52 pm on Oct 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can i make this toggleDiv expand, and collapse once the next one is opened?

right now they all can be opened at the same time, and it makes my links drop past my column....

<script language="javascript">
function toggleDiv(divid){
if(document.getElementById(divid).style.display == 'none'){
document.getElementById(divid).style.display = 'block';
}else{
document.getElementById(divid).style.display = 'none';
}
}
</script>

<li><a onclick="toggleDiv('kootenai');" href="javascript:;">Kootenai</a></li>
<div id="kootenai" style="display: none;">
Show hidden text here...!
</div>

mehh

4:16 pm on Oct 1, 2007 (gmt 0)

10+ Year Member



<script type="text/javascript">
var divIds=['kootenai', //a list of all the id's you want to toggle
'bar',
'foo'];

function toggleDiv(divid){
var i, div;
for(i=0; (div=document.getElementById(divIds[i])) ;i++){
if(divIds[i]!=divid){
div.style.display = 'none';
}else{
div.style.display = '';
}
}
}
</script>

untested. should work tho. Works the same as the old one