X Tutup
Skip to content

Commit 4a6d163

Browse files
committed
Css: Revert 24e5879
The workaround to be able to change !important styles broke the browser keeping the old CSS value if the new one was rejected. Patching it would involve a significant perf hit (~33%) so the initial patch needs to be reverted instead. Tests by m_gol & gibson042. (cherry-picked from 10e6542) Fixes #14836 Closes jquerygh-1532
1 parent 10e6542 commit 4a6d163

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/css.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,6 @@ jQuery.extend({
295295
// Support: IE
296296
// Swallow errors from 'invalid' CSS values (#5509)
297297
try {
298-
// Support: Chrome, Safari
299-
// Setting style to blank string required to delete "style: x !important;"
300-
style[ name ] = "";
301298
style[ name ] = value;
302299
} catch(e) {}
303300
}

test/unit/css.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ test( "css() explicit and relative values", 29, function() {
207207
});
208208

209209
test("css(String, Object)", function() {
210-
expect( 19 );
210+
expect( 20 );
211211
var j, div, display, ret, success;
212212

213213
jQuery("#nothiddendiv").css("top", "-1em");
@@ -242,15 +242,18 @@ test("css(String, Object)", function() {
242242
equal( ret, div, "Make sure setting undefined returns the original set." );
243243
equal( div.css("display"), display, "Make sure that the display wasn't changed." );
244244

245-
// Test for Bug #5509
246245
success = true;
247246
try {
248-
jQuery("#foo").css("backgroundColor", "rgba(0, 0, 0, 0.1)");
247+
jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" );
249248
}
250249
catch (e) {
251250
success = false;
252251
}
253-
ok( success, "Setting RGBA values does not throw Error" );
252+
ok( success, "Setting RGBA values does not throw Error (#5509)" );
253+
254+
jQuery( "#foo" ).css( "font", "7px/21px sans-serif" );
255+
strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px",
256+
"Set font shorthand property (#14759)" );
254257
});
255258

256259
test( "css(Array)", function() {
@@ -981,10 +984,20 @@ test( ":visible/:hidden selectors", function() {
981984
t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
982985
});
983986

984-
test( "Override !important when changing styles (#14394)", function() {
987+
test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function() {
988+
expect( 2 );
989+
990+
var el;
991+
el = jQuery( "<div></div>" ).css( "color", "black" ).css( "color", "fake value" );
992+
equal( el.css( "color" ), "black", "The old style is kept when setting an unrecognized value" );
993+
el = jQuery( "<div></div>" ).css( "color", "black" ).css( "color", " " );
994+
equal( el.css( "color" ), "black", "The old style is kept when setting to a space" );
995+
});
996+
997+
test( "Reset the style if set to an empty string", function() {
985998
expect( 1 );
986-
var el = jQuery( "<div style='display: block !important;'></div>" ).css( "display", "none" );
987-
equal( el.css( "display" ), "none", "New style replaced !important" );
999+
var el = jQuery( "<div></div>" ).css( "color", "black" ).css( "color", "" );
1000+
equal( el.css( "color" ), "", "The style can be reset by setting to an empty string" );
9881001
});
9891002

9901003
asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() {

0 commit comments

Comments
 (0)
X Tutup