Hi frnds,

I m using the below code...it is working fine...nothing prob in it..

just i want change the visibility of that div....here by default div is visible...but i want default div should be hidden.....plz look into the below code..

<html>
<head>
 
    <script language="javascript" type="text/javascript">
    function showHideDiv()
    {
        var divstyle = new String();
        divstyle = document.getElementById("div1").style.visibility;
        if(divstyle.toLowerCase()=="visible" || divstyle == "")
        {
            document.getElementById("div1").style.visibility = "hidden";
        }
        else
        {
            document.getElementById("div1").style.visibility = "visible";
        }
    }
    </script>   
</head>

<body>

    <div id="div1" class="divStyle">
        Show Hide Div 
    </div>
    
    <center>
      <a href="#" onclick="showHideDiv()" >Click Here</a>
    </center>
	
	
    
</body>
</html>

Recommended Answers

All 3 Replies

try with:

div1.style.display = 'none';

Either set the styles in the css for 'divStyle'
like

<STYLE>
...
...
. divStyle{
     ...
     ...	
     visibility:hidden;    
     ...
     ...
}
....
</STYLE>

Or you can set it in the style attribute of the div element as

<div id="div1" class="divStyle" style="visibility:hidden;">

hope this helps

Member Avatar for rajarajan2017
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<div id='imageSpace'><img src='images/image.jpg'></div>
<input type="radio" name="changer" value="show" onclick="document.getElementById('imagespace').style.display = '';"> Show<br>
<input type="radio" name="changer" value="hide" onclick="document.getElementById('imagespace').style.display = 'none';"> Hide
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.