$('#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
2010-08-14 06:01:23
+1
A:
$('#elementid').css('height')
This will return you the actual height set on the element via css with units intact.
Hasan Khan
2010-08-14 05:51:02
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
2010-08-14 06:12:41