Forum Moderators: open

Message Too Old, No Replies

Div Height Calculation

I need to determine the hight of a div after page load

         

ogbecker

6:21 am on Nov 6, 2007 (gmt 0)

10+ Year Member



Best to show in code and then explain.

<div style="display:none;width:250px;margin-left:-250px;position:absolute;background-color:#f1f1f1;" id="container">

<div id="myframe" style="filter: alpha(opacity=0); z-index:10; height: 100%; overflow: hidden; width: 250px;position: absolute;">
<iframe id="'eliframe'" style="z-index:10; width: 250px;" frameborder="0"></iframe>
</div>

<div id="overlay12" style="position: absolute;z-index:18;width:250px;border:1px solid #005cb1;position:absolute;background-color:#f1f1f1;">
-[CONTENT]-
</div>

<script type="text/javascript">
window.onload = getH;

function getH(){
var divh = document.getElementById("container").offsetHeight;
alert(divh);
}
</script>

</div>

So I need the height of the iframe to reflect the height of the div.
The Div height is based on the amount of content that is inserted into it on page load (so I can't set an absolute height).

The iframe is to allow the help popup to tile over dropdown menus in IE.

The script above doesn't return the height of the #container element it returns a "0".

I need it to figure out the height on page load, and I can't seem to do it for the life of me.

Please help!

daveVk

8:58 am on Nov 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Set myframe height to overlay12 height?

document.getElementById("myframe").offsetHeight = document.getElementById("overlay12").offsetHeight;

"container" has no height or content as internal divs are all absolute positioned.

ogbecker

9:01 am on Nov 6, 2007 (gmt 0)

10+ Year Member



Thanks, well I was trying to get the script to actually recall the correct height (hence the alert) after which I could apply it to the div. But it recall 0...so I don't know what to do.

daveVk

9:21 am on Nov 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var divh = document.getElementById("overlay12").offsetHeight;
alert( divh );
document.getElementById("myframe").offsetHeight = divh;

Welcome to forum