Pete Pete - 2 months ago 8
jQuery Question

get height from style attribute

Is there a way to get the height from a style attribute on a div?

<div style="height:100px;"></div>


I can't use
.height()
as this will just return me the current height of the element - I need to check if the style has been set and then get that height if it has

Answer

The easiest way is to go straight to the style property:

var heightStyleValue = $("selector for your element")[0].style.height;

You don't want to use jQuery's css function because that will give you the calculated height, not the value from the style object.

Comments