Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get CSS height value (rather than calculated height) in jQuery

Tags:

html

jquery

css

Assume that the height of an element is set to 'auto'. Trying to get the height in jQuery returns the calculated height. Is there a way to get the actual CSS value (auto) instead of the height in pixels?

$('#myDiv').height() // returns calculated height

See http://jsfiddle.net/7GrwJ/

like image 718
M.S Avatar asked Oct 25 '25 23:10

M.S


1 Answers

It is possible to retrieve the raw CSS value, see this fiddle for the result (tested in Firefox and Chromium)

I used this answer to get the raw css object, and this gist to emulate a required function that is only natively available to Webkit.

After that, accessing the property is easy:

css($('#myDiv')).height
like image 94
Yogu Avatar answered Oct 28 '25 16:10

Yogu