Posted by: prajapatinilesh | February 26, 2008

Get height value from the Css class

function getHightFromCss(tdObj) {
var height = ”;
//alert(tdObj.style.height); //it is just for only inline style
if ( tdObj.currentStyle ) {
//alert(tdObj.currentStyle.height);
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: ‘ + elt.style.height);
alert(‘Height as a Number: ‘ + parseInt(elt.style.height));
alert(‘Width as a String: ‘ + elt.style.width);
alert(‘Width as a number: ‘ + parseInt(elt.style.width));
</script>
The preceding code will alert the following:
1: “200px”
2: “200”
3: “50em”
4: “50”;

Thanks,
Nilesh Prajapati

Advertisements

Responses

  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.

    Simply:
    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.

    Mike


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Categories

%d bloggers like this: