japangreg
10-25-2002, 08:08 PM
Hey, everyone. I have a script to change the CSS display property of a div; so far, everything works fine except that I have to click twice on the "expand" button to get the property to switch. Any ideas of why this might be happening? Code is below.
function toggle(id){
if (document.getElementById(id).style.display == "none"){
document.getElementById(id).style.display = "block";
}else{
document.getElementById(id).style.display = "none";
}
}
The CSS I am using is as follows:
.expandButton{text-decoration:underline;
cursor : pointer;
}
#subMenu{display:none;
}
The code in the body looks like this:
<span class="expandButton" onClick="toggle('subMenu')">Expand</span>
<div id="subMenu">
Sub Menu is here
</div>
Any help is appreciated! :thumbsup:
Thanks!
japangreg
[EDIT]*PROBLEM SOLVED*
I just switched the conditionals and now it works like a dream. So now instead of: if (document.getElementById(id).style.display == "none"){
document.getElementById(id).style.display = "block";
}else{
document.getElementById(id).style.display = "none";
}
I have:if (document.getElementById(id).style.display == "block"){
document.getElementById(id).style.display = "none";
}else{
document.getElementById(id).style.display = "block";
Thanks to all who took the time to read this!
[EDIT]
function toggle(id){
if (document.getElementById(id).style.display == "none"){
document.getElementById(id).style.display = "block";
}else{
document.getElementById(id).style.display = "none";
}
}
The CSS I am using is as follows:
.expandButton{text-decoration:underline;
cursor : pointer;
}
#subMenu{display:none;
}
The code in the body looks like this:
<span class="expandButton" onClick="toggle('subMenu')">Expand</span>
<div id="subMenu">
Sub Menu is here
</div>
Any help is appreciated! :thumbsup:
Thanks!
japangreg
[EDIT]*PROBLEM SOLVED*
I just switched the conditionals and now it works like a dream. So now instead of: if (document.getElementById(id).style.display == "none"){
document.getElementById(id).style.display = "block";
}else{
document.getElementById(id).style.display = "none";
}
I have:if (document.getElementById(id).style.display == "block"){
document.getElementById(id).style.display = "none";
}else{
document.getElementById(id).style.display = "block";
Thanks to all who took the time to read this!
[EDIT]