Connecting Tech Pros Worldwide Help | Site Map

question about style.height

datactrl
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi, all

If I didn't set the height of an html element on a web page with html
attributes. Then obj.style.height always reports "0" even after the page has
completely rendered. Is there any way to get the actual height after being
rendered?

Jack


Ron
Guest
 
Posts: n/a
#2: Jul 23 '05

re: question about style.height


datactrl wrote:
[color=blue]
>Hi, all
>
>If I didn't set the height of an html element on a web page with html
>attributes. Then obj.style.height always reports "0" even after the page has
>completely rendered. Is there any way to get the actual height after being
>rendered?
>
>Jack
>
>
>
>[/color]
The following code will get the computed height in pixels:

var obj = document.getElementById("myObject");
var objHeight = null;
if(document.implementation.hasFeature("CSS", "2.0")) {
objHeight = document.defaultView.getComputedStyle(obj,
null).getPropertyCSSValue("height").getFloatValue( 5);
}
else if(obj.clientHeight!=null) {
objHeight = obj.offsetHeight;
}

Learn more about the W3C CSS interfaces at
http://www.w3.org/TR/DOM-Level-2-Style . IE's offsetHeight property was
found at
http://msdn.microsoft.com/workshop/a...fsetheight.asp
..
Closed Thread