Forum Moderators: open

Message Too Old, No Replies

Finding full height of outer div?

         

pkirkaas

5:35 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Hi;

Using Firefox:
I'm trying to get the height of my header, which looks something like this:

<div id="header">
<p>This is some text</p>
<div id="innerHeader">
blah, blah.
</div>
</div>

The problem is, when I do:

document.getElementById("header").offsetHeight;

It returns the height of the header paragraph, without the height of the nested "innerHeader".

Is there some general way to get the total height of the whole nested header div? I know I can work around it case by case, for example eliminating the inner div, or getting it's height and adding it to the outer div, but if there is a more elegant general approach, I'd like to find it.

Thanks for any insight,

Paul

Fotiman

6:03 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you are mistaken. I get the height of the entire header element (56 in Firefox).


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title></title>
</head>
<body>
<div id="header">
<p>This is some text</p>
<div id="innerHeader">
blah, blah.
</div>
</div>
<script type="text/javascript">
var header = document.getElementById('header');
var h = header.offsetHeight;
alert( h );
</script>
</body>
</html>

pkirkaas

3:10 pm on Jan 30, 2008 (gmt 0)

10+ Year Member



Okay, my bad -- the "innerHeader" was a float; that's why it didn't get picked up. Sorry & thanks. Your response made me look at what was going on more closely. It was defined in a cascading style sheet a few levels up.

Thanks again,

Paul