Ticket #11041 (closed bug: duplicate)
$('#elem').css('width') in percentage in jquery 1.5.2 vs 1.7.1
| Reported by: | strikernl2 | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I'm not actually sure that this is a bug or just intended changed behaviour between jQuery 1.5.2 and 1.6 (and thus 1.7.1), but here goes.
I'm in the process of upgrading a web application from jQuery 1.5.2 to 1.7.1. In jQuery 1.5.2, it was possible to get the percentage CSS value of an element using $('#elem').css('width'), if the element was inside another hidden element.
To be clear, I need the CSS value in PERCENTS and I don't know beforehand whether it will be in percents, or px, or em, or whatever.
For a simple test case, see here: http://jsfiddle.net/strikernl/y3P3A/
It seemed to work in 1.5.2, then no longer in 1.7.1. I added 1.6 in the test just to see if that still worked, and it didn't, so it broke somewhere between 1.5.2 and 1.6 I guess.
Change History
comment:1 Changed 17 months ago by dmethvin
- Status changed from new to closed
- Resolution set to duplicate
comment:3 Changed 17 months ago by anonymous
Sorry, I did look, could not find a matching ticket however. Thanks!
comment:4 Changed 7 months ago by tylerism@…
This is not a duplicate ticket. This needs to be fixed. It is returning pixels instead of percentage. The linked ticket is for a separate issue, when div is inside a hidden element
comment:5 follow-up: ↓ 6 Changed 7 months ago by dmethvin
.css() uses the browser's .getComputedStyle() which is supposed to get the computed styles in pixels, if not for some bug cases in various implementations. Fixing that is beyond the capability of jQuery, we don't have the information. This whole mess is under discussion in the W3C lists if you want to follow them.
Ref: http://lists.w3.org/Archives/Public/www-style/2012Jul/0282.html
comment:6 in reply to: ↑ 5 ; follow-up: ↓ 7 Changed 7 months ago by tylerism@…
That is very interesting. So you are saying that if I have a div whose width is 100% I cannot get that information back from JQuery? but selecting that div and running .width() or .css()?
comment:7 in reply to: ↑ 6 Changed 7 months ago by tylerism@…
Replying to tylerism@…:
That is very interesting. So you are saying that if I have a div whose width is 100% I cannot get that information back from JQuery? but selecting that div and running .width() or .css()?
SORRY! Meant to say "That is very interesting. So you are saying that if I have a div whose width is 100% I cannot get that information back from JQuery by selecting that div and running .width() or .css()?"
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
