Ticket #9945 (closed bug: wontfix)
Percentage Width Elements in Hidden Divs
| Reported by: | kgorsky | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 1.next |
| Component: | css | Version: | 1.6.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Lets say you have an element with a css width of 94%.
And lets say you put that element inside a div with the css display value of "none".
When you call width() on the first element, you are returned a pixel value based on the percent, ie, 94px.
Change History
comment:1 follow-up: ↓ 5 Changed 23 months ago by rwaldron
- Priority changed from undecided to low
- Resolution set to invalid
- Status changed from new to closed
- Component changed from unfiled to css
comment:2 Changed 23 months ago by rwaldron
- Status changed from closed to reopened
- Resolution invalid deleted
comment:3 Changed 23 months ago by rwaldron
- Status changed from reopened to closed
- Resolution set to duplicate
comment:5 in reply to: ↑ 1 Changed 23 months ago by kgorsky
Replying to rwaldron:
jQuery intentionally normalizes all css property values to pixel units
If you look the example in the link I gave, the actual width that should be returned is not 94px.
When the parent element is hidden, jQuery returns the percentage value (ie, 94%) as a pixel value (ie, 94px) even though the ACTUAL width may be 300px.
comment:6 Changed 23 months ago by rwaldron
- Status changed from closed to reopened
- Resolution duplicate deleted
Thanks for the heads up.
Confirmed, further reduced: http://jsfiddle.net/rwaldron/xTgvF/
comment:8 Changed 23 months ago by rwaldron
- Priority changed from low to high
- Milestone changed from None to 1.7
comment:9 Changed 20 months ago by mikesherov
so, this comes down to just returning a value like null,false,undefined, or 0 when a unit other than px is specified on a child of a hidden div.
Question is, what value should it return?
comment:10 Changed 20 months ago by mikesherov
yeah, percentage values for any of width,padding,margin,or border will result in the answer being goofy. If any of them contain percentages, the whole calculation should report 0.
This is also a needsdocs.
Very similar to #10117
comment:11 Changed 20 months ago by timmywil
- Owner set to timmywil
- Status changed from open to assigned
- Milestone changed from 1.7 to 1.next
Per meeting, pushing this until we have time to refactor.
comment:12 Changed 12 months ago by mikesherov
#11944 is a duplicate of this ticket.
comment:13 Changed 8 months ago by anonymous
Hello ! Are you still working on this bug ?
comment:14 Changed 8 months ago by anonymous
We need a solution for this bug, please help us!
comment:15 Changed 8 months ago by timmywil
- Owner timmywil deleted
- Status changed from assigned to open
comment:16 Changed 8 months ago by pbramos
I'm going to look at this issue, but wanted to touch base with anyone who might have made progress here or has any insight before I do.
comment:17 Changed 7 months ago by pbramos
Pull request:
comment:18 Changed 6 months ago by mikesherov
- Status changed from open to closed
- Resolution set to wontfix
There is no good answer here for this bug, and it's not a good practice to be querying hidden elements for height/width info anyway. I'm going to close this as wontifx and open a docs issue.
comment:19 Changed 6 months ago by mikesherov
Docs issue here: https://github.com/jquery/api.jquery.com/issues/197
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

jQuery intentionally normalizes all css property values to pixel units