Can jquery return height of an element as a percentage?
You can use .height()
, which returns just the number (i.e, without the unit symbol). 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
);
you can convert get height in px and convert them to percenatge
1em = 12pt = 16px = 100%