Hi guys, im a super-noob at this website stuff and i really need a little help. I have been using some script to toggle show/hide text but it starts off with the text being seen and you have to click it to hide <script type="text/javascript"> function toggleDisplay(mySpan) { // acquire a reference to the target div by looking for first sibling div var target = mySpan.parentNode.parentNode.getElementsByTagName("DIV")[0]; // hide or show div, and swap the text in the span if (target.style.display!="none") { // hide the target div target.style.display = "none"; mySpan.innerHTML = "<U>REVEAL THE ABOVE</U>"; } else { // reveal the target div target.style.display = "block"; mySpan.innerHTML = "<U>HIDE THE ABOVE</U>"; } } </script> <div class="showHideContainer"> <div style="border: 1px solid black"> blah blah blah </div> <script type="text/javascript"> document.write("<p style=\"margin-top:0; text-align:center\"><span " + "onclick=\"toggleDisplay(this);\" style=\"cursor:pointer\">Hide " + "the above</span></p>\n"); </script> </div> Code (markup): But to help unclutter my page, i wanted to know how to change it so that the text starts off hidden, having to be clicked to reveal. any help would be really appreciated
<script type="text/javascript"> function toggleDisplay(mySpan) { // acquire a reference to the target div by looking for first sibling div var target = mySpan.parentNode.parentNode.getElementsByTagName("DIV")[0]; // hide or show div, and swap the text in the span //alert(target.style.display); if (target.style.display == "none") { // reveal the target div target.style.display = "block"; mySpan.innerHTML = "<U>HIDE THE ABOVE</U>"; } else { // hide the target div target.style.display = "none"; mySpan.innerHTML = "<U>REVEAL THE ABOVE</U>"; } } </script> <div class="showHideContainer"> <div style="border: 1px solid black; display:none"> blah blah blah </div> <p style="margin-top:0; text-align:center"> <span onclick="toggleDisplay(this);" style="cursor:pointer">Reveal the above</span></p> </div> HTML: