View Full Version : body onload hide , problem with onclick show

Nov 23rd, 2009, 07:44 PM
hi all im trying to hide a div on page load,

ive used this.

<script type="text/javascript">
function hideDiv(){
document.getElementById('sidebar').style.display = "none";

and this in the body tag

<body onload="javascript:hideDiv()">

it works fine hiding the div named sidebar, problem comes when i try to then use an Onclick event to show the hidden div, it just wont show.

can this be done?

please help if you can this work has to be in soon :)

Nov 23rd, 2009, 07:51 PM
to try and get the div to show onclick i have used the behavious in dreamweaver if this helps?

here is the addition its made to the javascript

<script type="text/javascript">
function MM_showHideLayers() { //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }

and here is the body

<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('icon','','images/iconhover.png',1)"><img src="images/icon.png" name="icon" width="40" height="40" border="0" id="icon" onclick="MM_showHideLayers('sidebar','','show')" /></a>

Nov 25th, 2009, 09:18 AM
I think ...style.display = "none" doesn't create the sidebar, that's why it is invisible. Use ...style.visibility="hidden" for creating invisible sidebar.