Ticket #4427 (closed bug: fixed)
jQuery.css(name) returns inconsistent results
| Reported by: | skyde | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | |
| Component: | css | Version: | 1.3.2 |
| Keywords: | css | Cc: | |
| Blocking: | Blocked by: |
Description
jQuery.css(name) returns inconsistent results depending on whether name is written camel-cased or hyphened, when !important style rules apply.
To repeat:
1) add a !important style rule to an element, for example background-color: #000 !important
2) change the property with jQuery, for example $(element).css('background-color', '#fff');
3) $(element).css('background-color') returns now #000, while $(element).css('backgroundColor') returns differently #fff
Firefox 3.0.7, Opera 9.52 and IE7 were tested to work this way, on webkit-based browsers (Safari 4 and Chrome 1 tested) $(element).css() overrides !important rules with both writing styles.
I don't know which one is the correct way (styles applied with $.css can be seen as inline styles, in which case they should be overridden by !important rules), but $.css should return consistent values in any case, not depending on writing style :)
See attachment for tests.
Attachments
Change History
comment:2 Changed 3 years ago by rwaldron
- Priority changed from minor to undecided
- Status changed from new to open
- Component changed from core to css
- Milestone 1.4 deleted
Needs further review
comment:3 Changed 2 years ago by danheberden
- Status changed from open to closed
- Resolution set to fixed
I can't reproduce this:
http://jsfiddle.net/danheberden/NpAq4/3/
there seems to be no odd reporting for $.fn.css() using one or the other. Also, !important styles should remain as they are, well, important.
Checked in chrome 10, chromium 11, ff3, ff4, opera 11, safari 5, ie6-9rc1, and even on my iphone. All works as expected :D
comment:4 Changed 2 years ago by Azatoth
QUnit test for overriding important css declarations, references #4427
Changeset: 1299e89dcd803ee0ed48622c716dc3d4c8567cb7
comment:5 Changed 2 years ago by timmywil
Azatoth: your pull was landed, but is causing fails in firefox 4 and opera 11.01.
comment:6 Changed 2 years ago by jeresig
Revert "QUnit test for overriding important css declarations, references #4427"
This reverts commit 1299e89dcd803ee0ed48622c716dc3d4c8567cb7.
Conflicts:
test/unit/css.js
Changeset: 312df0441b16981dd697d74fcbc1e1f212b47b7e
comment:7 Changed 2 years ago by danheberden
From the spec: http://www.w3.org/TR/DOM-Level-2-Style/css#CSS-DocumentCSS
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

