I'm trying to make a collapsible section in a webpage. Right now, all the code for it is working except for a check on style.visibility:
- Code: Select all
if (document.getElementById(contentID).style.visibility == 'visible')
Here's the script:
- Code: Select all
function toggleCollapse(contentID, choiceID) {
if (document.getElementById(contentID)) {
if (document.getElementById(contentID).style.visibility == 'visible') {
document.getElementById(contentID).style.height = 'auto';
document.getElementById(contentID).style.visibility = 'visible';
changeChoice(choiceID, true);
}
}
}
Here's the relevant CSS:
- Code: Select all
.Dept_Collapsed {
background-image: url(Files/Dept%20Expand.gif);
width: 545px;
height: 37px;
}
.Content_Collapsed {
height: 0px;
visibility: hidden;
}
Here's the body:
- Code: Select all
<div id="1" class="Dept_Collapsed" onClick="toggleCollapse('2', '1')"></div>
<div id="2" class="Content_Collapsed">Test 2</div>
How do I fix it so I can compare if it's hidden or not:?:


