user1160126 user1160126 - 1 year ago 46
Javascript Question

on click show div getting error

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

<script type="text/javascript">
var bool = 0;
function showDiv(){
document.getElementById(show).style.visibility = "hidden";
}else if(bool==0){
document.getElementById(show).style.visibility = "visible";
<input type="button" value="click" onclick="showDiv();" />

<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>


Answer Source

You're missing the quotes for the id argument for getElementById()

document.getElementById('show').style.visibility = "hidden";

Also the id attribute name is missing on the <div>


Should be this:

<div id="show">


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download