# Javascript - hide div on initial page load

**URL:** <https://forum.kirupa.com/t/javascript-hide-div-on-initial-page-load/259086>\
**Category:** Uncategorized\
**Created:** [April 30, 2008, 11:56pm UTC](https://forum.kirupa.com/t/javascript-hide-div-on-initial-page-load/259086 "2008-04-30T23:56:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moodie](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/moodie/32/1905_2.png) [@moodie](https://forum.kirupa.com/u/moodie)\
**Post date:** [April 30, 2008, 11:56pm UTC](https://forum.kirupa.com/t/javascript-hide-div-on-initial-page-load/259086/1 "2008-04-30T23:56:14Z")

</div>

I’m building a site and using this bit of code to hide a div on click

```auto
{
   var obj = document.layers ? document.layers[szDivID] :
   document.getElementById ? document.getElementById(szDivID).style :
   document.all[szDivID].style;
   obj.visibility = document.layers ? (iState ? "show" : "hide") :
   (iState ? "visible" : "hidden");
}

```

its all working fine, but i was wanting to know if it was possible to hide a div on the initial page load, but just once off. Basically when the site loads, there is an empty #content div, so I wan to hide it, but that same div holds the content for all the other pages, so it would need to be visible after the first page.

this is the site [http://www.blockprojects.com/index.php](http://www.blockprojects.com/index.php)

any help would be great.

---

<div class="post-metadata">

**Author:** ![jkanakaraj](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jkanakaraj](https://forum.kirupa.com/u/jkanakaraj)\
**Post date:** [May 16, 2008, 8:23am UTC](https://forum.kirupa.com/t/javascript-hide-div-on-initial-page-load/259086/2 "2008-05-16T08:23:26Z")

</div>

You can create a function to do this, and add an event handler to the body tag.

```auto
<script>
function hideDiv(){
document.getElementById('IDGOESHERE').style.display = "none";
}
hideDiv()
</script>

```

---

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [May 20, 2008, 2:08pm UTC](https://forum.kirupa.com/t/javascript-hide-div-on-initial-page-load/259086/3 "2008-05-20T14:08:14Z")

</div>

[quote=jkanakaraj;2327028]You can create a function to do this, and add an event handler to the body tag.

```auto
<script>
function hideDiv(){
document.getElementById('IDGOESHERE').style.display = "none";
}
hideDiv()
</script>

```

[/quote]

Actually, the onLoad attribute in the tag, and a call to the function there, should be able to assist you. This is for the body part.

```auto
<script>
// Check for INT value. 
var numInt = 1;

// I'd put this code into a separate script so you don't have to re-write this. Javascript can use variables declared on(Level 2: In the Head) and off(Level 3: Separate file) of the page.
// Variable.
function chckFrInt()
{// Check to see if it's the first time.
  if(numInt == 1)
  {// if it IS the first time
    hideDiv()
  }
}

function hideDiv(){
document.getElementById('IDGOESHERE').style.display = "none";
}
hideDiv()
</script>
<body onload="javascript:chckFrInt()">

```
