Ticket #8741 (closed bug: duplicate)
.css("height") returns computed height
| Reported by: | Ivellina | Owned by: | Ivellina |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | css | Version: | 1.5.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
As of version 1.5.1 and 1.5.2 .css("height") returns computed height instead of the style property height. For example :
<table id="anId" style="height: 200px">...
accessed by:
$("anId").css("height")
returns the real table size instead of 200px.
It works fine in version 1.3.2. The problem is always reproducible on Firefox 3.0.5 and IE 8 on Windows XP.
Change History
comment:2 Changed 2 years ago by Ivellina
- Status changed from pending to new
Hi,
Thanks for your quick response.
I made an example to show you the problem we have. http://jsfiddle.net/FTjzm/1/
If you change the version to 1.3.2 you will see that it works correctly.
Ivelina
comment:3 Changed 2 years ago by timmywil
- Keywords needsreview added
- Status changed from new to open
- Version changed from 1.5.1 to 1.5.2
After some investigation, it seems we are always using the computed in jQuery.css. This may be intended behavior.
comment:4 Changed 2 years ago by Ivellina
If this is the intended behavior can you point me to the method I have to use in order to get the css height attribute?
comment:5 Changed 2 years ago by timmywil
You will be able to use prop in 1.6, but for now you can use raw js. http://jsfiddle.net/timmywil/FTjzm/6/ Nevertheless, this still needs review as to whether always getting the computed value is intended behavior because I can't say for sure myself.
comment:6 Changed 2 years ago by Ivellina
Thank you for your suggestion. It works for us and we will apply it as a fix until we are waiting for version 1.6.
comment:7 Changed 2 years ago by timmywil
- Priority changed from undecided to low
- Component changed from unfiled to css
comment:8 Changed 2 years ago by dmethvin
Yes it seems logical that .height() should return the height in pixels and .css("height") should return the non-computed CSS string (auto, 20em, etc.) for height. The problem is that other measurements (e.g., borderRightWidth) don't have a way to get computed vs. non-computed values via the jQuery API. It would be a serious problem IMO to return non-computed values for those.
I know it's been discussed quite a bit in the past but we need to document and justify why it works this way in the docs if it's to stay this way.
comment:9 Changed 2 years ago by timmywil
- Keywords needsreview removed
- Status changed from open to closed
- Resolution set to duplicate
comment:10 Changed 2 years ago by timmywil
Duplicate of #7486.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I created a test case based on your description and was unable to reproduce your issue. I checked in IE8. http://jsfiddle.net/timmywil/YxTn2/. Please provide a test case on jsfiddle or update mine to demonstrate the problem.