Posted by: prajapatinilesh | February 26, 2008

Get height value from the Css class

function getHightFromCss(tdObj) {
var height = ”;
//alert(; //it is just for only inline style
if ( tdObj.currentStyle ) {
height = tdObj.currentStyle.height;
} else if ( document.defaultView.getComputedStyle){
//alert(document.defaultView.getComputedStyle(tdObj,”) .height);
height = document.defaultView.getComputedStyle(tdObj,”) .height;
return height
you can get this way other property value from the css class.

//to get only integer value from the style information.
<div id=”thing” style=”height:200px; width:50em;”>
<script type=”text/javascript”>
var elt = document.getElementById(‘thing’);
alert(‘Height as a String: ‘ +;
alert(‘Height as a Number: ‘ + parseInt(;
alert(‘Width as a String: ‘ +;
alert(‘Width as a number: ‘ + parseInt(;
The preceding code will alert the following:
1: “200px”
2: “200”
3: “50em”
4: “50”;

Nilesh Prajapati



  1. This is way over my head but I can almost figure it out. Here’s what I am after. I can set the PHP style the php templates. What I need is to be able to get the height of what we’ll call content within the page.

    I want to set the sidebars the same height as this.

    1 – get the content height
    2 – set the sidebar to that height in the sidebar.php

    I think your code can do this but not sure how to adapt it because I lack jQuery skills. Is what I want possible?

    Any help is appreciated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: