Opened 11 years ago
Closed 11 years ago
#13088 closed bug (fixed)
under IE8, $(selector).attr('style') always return lowercase string
Reported by: | Owned by: | mikesherov | |
---|---|---|---|
Priority: | low | Milestone: | 1.9 |
Component: | css | Version: | 1.8.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
On IE8, due to $(selector).attr('style') always return lowercase string, this will lead background image missing.
I checked the source code, it's below: if ( !jQuery.support.style ) {
jQuery.attrHooks.style = {
get: function( elem ) {
Return undefined in the case of empty string Normalize to lowercase since IE uppercases css property names
return elem.style.cssText.toLowerCase() undefined; }, set: function( elem, value ) {
return ( elem.style.cssText = value + "" );
}
};
}
see this part: Normalize to lowercase since IE uppercases css property names
undefined; |
This works in most cases except when style contains URL portions, for example: background-image:url('xxx.com/Path/MyImage.png') the URL is case-sensitive, so above process will return lowercase string lead to the image can't be loaded.
Change History (10)
comment:1 Changed 11 years ago by
comment:2 follow-up: 3 Changed 11 years ago by
Owner: | set to superbible@… |
---|---|
Status: | new → pending |
This seems like a choice between two horrible alternatives, one of which people have come to expect. Most code is going to really dislike uppercase style names. I understand that lowercasing file names can corrupt them.
Why look at the style information this way? Can't you just get it through .css()
if you need the URL with the original case?
comment:3 Changed 11 years ago by
Replying to dmethvin:
This seems like a choice between two horrible alternatives, one of which people have come to expect. Most code is going to really dislike uppercase style names. I understand that lowercasing file names can corrupt them.
Why look at the style information this way? Can't you just get it through
.css()
if you need the URL with the original case?
We build a WYSIWIG theme designer let user to customize their own theme, so user dynamically set css propery to elements, then we need to save them, so it's very simple to get what user change and need to save by $(element).attr('style'). So to use .css() is not suitable. If use prop('style'), it'll get more things than I want. Now I just add a patch to JQuery by disabled the code mentioned in the bug report.
comment:4 follow-up: 7 Changed 11 years ago by
Thanks for contributing!
If we really wanted to fix this, it requires splitting cssText, iterating over each declaration, fixing just the property name by actually camel casing it properly (as opposed to just lower casing it, which is impossible without a map of proper casings), and then joining together.
Instead, as dmethvin points out, just use .css(). Or if you need the specified inline cssText, use [0].style.cssText (native). In fact, we should probably remove this attrHook altogether, as its pretty archaic at this point and in fact just wrong.
Thoughts on removing it, anyone?
comment:5 Changed 11 years ago by
Removing it saves us some bytes, although I can see that breaking code (suddenly, UPPERCASE). I suppose though that we are clearly destroying information by lowercasing the text. If someone wants to lowercase it themselves they can still do that. So my vote would be to remove this.
comment:7 Changed 11 years ago by
Replying to mikesherov:
Thanks for contributing!
If we really wanted to fix this, it requires splitting cssText, iterating over each declaration, fixing just the property name by actually camel casing it properly (as opposed to just lower casing it, which is impossible without a map of proper casings), and then joining together.
Instead, as dmethvin points out, just use .css(). Or if you need the specified inline cssText, use [0].style.cssText (native). In fact, we should probably remove this attrHook altogether, as its pretty archaic at this point and in fact just wrong.
Thoughts on removing it, anyone?
Thank you for telling me [0].style.cssText. I think it's OK to remove it if it's not easy to make it work correctly.
comment:8 Changed 11 years ago by
Component: | unfiled → css |
---|---|
Milestone: | None → 1.9 |
Priority: | undecided → low |
Status: | pending → open |
comment:9 Changed 11 years ago by
Owner: | changed from superbible@… to mikesherov |
---|---|
Status: | open → assigned |
comment:10 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #13088: under IE8, $(selector).attr('style') always return lowercase string
Changeset: abead1c86b75d376544e52cd916031a67caf2c34
I think we should remove this code. And I didn't find it in JQuery1.4.4, which works for me.