Click to See Complete Forum and Search --> : Getting the CSS Height of a Div


Pilau
March 7th, 2009, 05:50 AM
Hi :)
I am facing a problem of getting the CSS height and width values of a DIV element for nearly two days now. I have tried all kinds of methods but I couldn't get it work.

I have a DIV which is defined by a CSS class in an external CSS file. The dimensions are 300x300. The thing is, I need to get the values inside the code.

How do I do that? Thanks!

PeejAvery
March 7th, 2009, 09:50 AM
Use the offsetHeight property.

You really should try a Google search next time. It would have taken you about 15 seconds to find the answer (http://www.google.com/search?source=ig&hl=en&rlz=&q=javascript+div+height&btnG=Google+Search&aq=f).

Pilau
March 7th, 2009, 12:52 PM
Well, just for your information, I've been working on this problem for two days before I posted it here. That's first.

Second, the offsetHeight property calculates the height of the element after the rendering, i.e. adding the spacing values (padding, borders etc.). So this is not good for me.

But apparently all I had to do was change something in my code. I used getComputedStyle. Google that up.