I have a DIV I want to adjust its size regarding the window size. So I have a javascript method that returns the newsize to apply. But I don’t see how I can define that size to the div without having to wait the end of page load.
I mean, I have some long loading objects on the page, so if I use the window.onload way to set the size, I have a div with a bad size at the start, then when the page is loaded, the div is resized. Baaad looking.
I’d like to set that size as soon as the page is displayed, with something like :
<div id="myid" style="width:myjavascript_Getcorrectsize();">
How would I do such a thing ?
You don’t have to wait for the
windowloadevent, or even for the “ready” events that some libraries provide. Just put your script block after thedivin question, and you will be able to access thatdivvia the DOM to set its size. E.g.:Live demo
References:
That said, if you can possibly set the size via CSS, you’d be better off. But I expect you’ve already found that for some reason you can’t do that.