# Setting div size to browser height with javascript

**URL:** <https://forum.kirupa.com/t/setting-div-size-to-browser-height-with-javascript/214209>\
**Category:** Uncategorized\
**Created:** [January 26, 2007, 10:18am UTC](https://forum.kirupa.com/t/setting-div-size-to-browser-height-with-javascript/214209 "2007-01-26T10:18:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Binji](https://avatars.discourse-cdn.com/v4/letter/b/cdc98d/32.png) [@Binji](https://forum.kirupa.com/u/Binji)\
**Post date:** [January 26, 2007, 10:18am UTC](https://forum.kirupa.com/t/setting-div-size-to-browser-height-with-javascript/214209/1 "2007-01-26T10:18:18Z")

</div>

I have a site where i want to set the div size using javascript. So far i have this:

```auto

var elTekst = document.getElementById("tekst");
elTekst.style.height = document.body.offsetHeight;

```

which should work, but everytime i run it the div gets only one line high. If I use alert(document.body.offsetHeight);  
it says 0. How is that possible? Im really puzzled here so i would appreciate your help.

edit: im running the script from “body onLoad” tag if that helps
