3

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/

M.S
  • 1,562
  • 1
  • 13
  • 22

1 Answers1

4

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
Community
  • 1
  • 1
Yogu
  • 8,629
  • 4
  • 33
  • 53
  • Of course it's possible, but is this a practical solution? +1 just for making me chuckle. – isherwood Oct 16 '13 at 20:04
  • What is "practical"?? – davidkonrad Oct 16 '13 at 20:06
  • Whether it is practical depends completely on the OP's requirements. I admit that at least in Firefox it is not performant because it parses all CSS files. If you use it multiple times, you should implement some caching. – Yogu Oct 16 '13 at 21:44