Hi i need some help with editing show/hide code it is works fine with me but it is show the content every time i refresh the page what i want is to be the conetent hidden till i click on the link to show the content so every time i refersh the page no thing appear untill i click on the show link. <head>tag <script type="text/javascript"> <!-- var storedDiv = null; function getDiv(oID) { if(document.getElementById) { return document.getElementById(oID); } else if( document.all ) { return document.all[oID]; } else { return null; } } window.onload = function () { for( var i = 0, y; y = getDiv('ans'+i); i++ ) { y.style.display = 'none' } }; function toggleInfo(oID) { var oDiv = getDiv(oID); if( !oDiv ) { return; } oDiv.style.display = (oDiv.style.display=='none') ? 'block' : 'none' if( storedDiv && storedDiv != oDiv ) { storedDiv.style.display = 'none' } storedDiv = oDiv; } //--></script> in <body>tag <span style="cursor: hand; cursor: pointer" onclick="toggleInfo('ans0');"> >> Hide/show content </span><br><br> <div id="ans0"> content </div>
<script> function toggleInfo(myID){ if(document.getElementById(myID).style.display=='none'){ document.getElementById(myID).style.display='block'; } else { document.getElementById(myID).style.display='none'; } } </script> <span style="cursor: hand; cursor: pointer" onclick="toggleInfo('ans0');"> >> Hide/show content </span><br><br> <div id="ans0"> content </div>
solve this problem using cookie set cookie value 1 when your div is visible and set cookie value 0 when div is hidden now on page load check the value of cookie if 1 then set your div visible and if cookie value is 0 set div hidden Setting Cookie Using javaScript document.cookie = "name=value; expires=date; path=path; domain=domain; secure"; i think this will solve your problem