April 14, 2012
on click show div getting error
Question by user1160126
am very sorry for this new bie question, when i click on the lick the div should open when i click again it should close the div..please help me on this
<html>
<head>
<script type="text/javascript">
var bool = 0;
function showDiv(){
if(bool==1){
bool=0;
document.getElementById(show).style.visibility = "hidden";
}else if(bool==0){
bool=1;
document.getElementById(show).style.visibility = "visible";
}
}
</script>
</head>
<body>
<input type="button" value="click" onclick="showDiv();" />
<div="show">
<p>it is okay it is okay it is okay it is okay it is okay it is okay it is okay it is okay</p>
</div>
</body>
</html>
Answer by Gabe
Answer by Starx
When you are referring to
document.getElementById(show).style.visibility
The show
refers to a variable, but you are trying to get it as a string, so you should get it quoted
document.getElementById('show').style.visibility