M.S
M.S

Reputation: 1610

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

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/

Upvotes: 4

Views: 1425

Answers (1)

Yogu
Yogu

Reputation: 9445

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

Upvotes: 5

Related Questions