Setting div size to browser height with javascript

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


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