Click to See Complete Forum and Search --> : Changing size of div with javascript


webuser123
01-29-2010, 04:39 PM
Hi,

I have an absolute positioned div within a relative positioned div and would like to determine the height of the absolute div dynamically with some javascript. Basically I would like to set the height of the relative div to the size of the absolute div after I determine what the height is.

If I give var document.getElementById("divName").style.height , I get nothing back as a value. The absolute positioned div has no height to begin with. It just expands based on its content. Also, I'm using an external stylesheet in my webpage.

How can I get this value? Thanks!

Webnerd
01-29-2010, 07:31 PM
document.getElementById("divName").offsetHeight

webuser123
01-30-2010, 05:05 PM
Thanks, what is the difference between height and offsetheight? Will this give me the actual height of the div?

webuser123
02-01-2010, 11:41 AM
thank you, that worked!

Webnerd
02-01-2010, 05:57 PM
offset dimensions are the calculated dimensions of the object by the browser. You can also get:

offsetWidth
offsetTop
ofsetLeft

Be advised that offsets are literally that, they are the offset from their parent element so some scripting is needed to traverse offsets for a literal page X and Y position.