Professional javascripters plz help or illl be screwed at work.....plz guys.....

I have made this sliding div....but i am having a big problem.....i dont want the div to appear in the first place....but in the code below its is already open when the page refreshed....I want it to open when i click on toggle.....n i cant understand what shud i do for that.....i have tried giving the "visibility:hidden;" to the 'testDiv'...after that it doesnt show up....but there is a whitespace of the div's size instead of the div itself......plz help....my code is below.....(i have made this with the help of a tutorial)....i'm kind of new at javascript.....

plz help......

Thanks

<html>
<head>
    <script language="javascript">
var active = 1;
var height = 100;
function toggle_visible() {
    if(active == 0) {
        active = 1;
        divPlusOne();                
    } else if(active == 1){
        active = 0;    
        divMinusOne();
    }
}

function divMinusOne() {
    if(height >= 20) {
        height = height - 1;
        document.getElementById('testDiv').style.height=height + 'px';
        window.setTimeout('divMinusOne()', 1);
    } else {
        document.getElementById('testDiv').style.visibility="hidden";
    }
} 

function divPlusOne() {
    if(height <= 100) {
        document.getElementById('testDiv').style.visibility="visible";    
        height = height + 1;
        document.getElementById('testDiv').style.height=height + 'px';        
        window.setTimeout('divPlusOne()', 1);
    }
}
</script>
    <title>JavaScript test</title>   
</head>
<body>
    <div id="testDiv">And here is my very slick menu!</div>
    <a href="#" onClick="toggle_visible()">Toggle</a>
</body>
</html>

The div should look like this if you want it to be hidden in the first place.

<div id="testDiv" style='visibility:hidden'>

The div should look like this if you want it to be hidden in the first place.

<div id="testDiv" style='visibility:hidden'>

i did that...but it shows a white space same size as the div.....thats where i'm stuck.......

i did that...but it shows a white space same size as the div.....thats where i'm stuck.......

You need to toggle the rendering and not visibility. Even invisible elements takes up space on the page. Use the "display" property to create invisible elements that do not take up space.

<div id="testDiv" style="display: none;">Content</div>

It worked.......thank you so much....u helped me big time......i cant believe i dint try that tho......but anywayz thanks alot.....

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.