tags:

views:

34

answers:

3

$('#my_div').height('50%') will set the height but how can you retrieve the divs current height as a percentage?

A: 

you can convert get height in px and convert them to percenatge

1em = 12pt = 16px = 100%
Ok, I was thinking something like this would be the only way. Thanks
Dennis_M
+1  A: 
$('#elementid').css('height')

This will return you the actual height set on the element via css with units intact.

Hasan Khan
any way to get that to return a percentage?
Dennis_M
A: 

You can use .height(), which returns no units -- just the number. Perfect for percentage, which of course needs no units. From the docs:

The .height() method is recommended when an element's height needs to be used in a mathematical calculation.

So you can try something like this:

var height_pct = Math.round( 
    $('#my_div').height() / 
    $('#my_div').parent().height() * 100
    );
Ken Redler