Side navigation
#11041 closed bug (duplicate)
Opened December 16, 2011 09:24AM UTC
Closed December 16, 2011 04:35PM UTC
Last modified October 24, 2012 09:53PM UTC
$('#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: | ||
Blocked by: | Blocking: |
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.
Attachments (0)
Change History (7)
Changed December 16, 2011 04:35PM UTC by comment:1
resolution: | → duplicate |
---|---|
status: | new → closed |
Changed December 16, 2011 06:29PM UTC by comment:3
Sorry, I did look, could not find a matching ticket however. Thanks!
Changed October 24, 2012 09:20PM UTC by comment:4
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
Changed October 24, 2012 09:38PM UTC by comment:5
.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
Changed October 24, 2012 09:52PM UTC by comment:6
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()?
Changed October 24, 2012 09:53PM UTC by comment:7
Replying to [comment:6 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()?"