View Full Version : Easy script to hide or show a div BUT start with all stuff hiden

Mar 14th, 2007, 05:26 PM
Hi there guys
been hunderds of posts about showing and hiding divs

i just want a simple code that will start with 1 div hidden
and then i click on a link show details and it shows off

but it has to start hidden 1st

can any one help me

this is the code i have at the moment and it works to hide and stuff
but i dont know enough to make it hide at a start

<!DOCTYPE WML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script type="text/javascript">
var current = "1";
function pageSwitch(id){
if(!document.getElementById) return false;
var div = document.getElementById("page"+id);
var curDiv = document.getElementById("page"+current);
curDiv.style.display = "none";
div.style.display = "block";
current = id;

<head> <title>Testmymobile.net - Advanced</title></head>
<div class="centre">

<a href="#" onclick="pageSwitch(1); return false;">Show Details</a>
<a href="#" onclick="pageSwitch(2); return false;">Hide Details</a>

<div id="page1">
<script type="text/javascript" language="JavaScript">
document.write ('1st '+filesize +'kb took ' + m1 + 'ms = ' + cps1 + ' KB/sec, approx ' + kps1 + ' Kbps, <b>' + mps1 + '</b> Mbps <br> ',
'2nd '+filesize +'kb took ' + m2 + 'ms = ' + cps2 + ' KB/sec, approx ' + kps2 + ' Kbps, <b>' + mps2 + '</b> Mbps <br><br> ');
<div id="page2">
<br />

<script type="text/javascript" language="JavaScript">
document.write ('<b>Please </b> provide us with some additional information<br>',
'Click \<a href=speedtestresults-advanced.php?&cps3='+cps3+'\x3eHERE<\/a\x3e to help us out');

var divs = document.getElementById("information").getElementsByTagName("div");

for(i = 0; i < divs.length; i++)
divs[i].style.display = "none";
document.getElementById("page1").style.display = "block";



if you dont understand that code like i did
do u have an easier code i could use ?


Mar 14th, 2007, 05:30 PM
<div id="page1" style="display:none;">
or much better put it in CSS.

<style type="text/css">
#page1 {
<div id="page1">

Mar 14th, 2007, 05:48 PM
it was really simple

u make me feel dumb now