question about style.height

D

datactrl

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
 
R

Ron

datactrl said:
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
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/author/dhtml/reference/properties/offsetheight.asp
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top