From a5063ee2a1eb22a66f0ae9b36f89935cf7c8a34b Mon Sep 17 00:00:00 2001 From: Lihan Li Date: Sun, 29 Sep 2013 12:06:32 -0400 Subject: [PATCH] Fix #14394: Changing style !important in webkit. Close gh-1385. (cherry picked from commit 24e587929f62428e1959b10aace6dc4fd65ab397) Conflicts: src/css.js --- src/css.js | 7 +++++-- test/unit/css.js | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/css.js b/src/css.js index 09d789168..b18f82202 100644 --- a/src/css.js +++ b/src/css.js @@ -292,9 +292,12 @@ jQuery.extend({ // If a hook was provided, use that value, otherwise just set the specified value if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) { - // Wrapped to prevent IE from throwing errors when 'invalid' values are provided - // Fixes bug #5509 + // Support: IE + // Swallow errors from 'invalid' CSS values (#5509) try { + // Support: Chrome, Safari + // Setting style to blank string required to delete "style: x !important;" + style[ name ] = ""; style[ name ] = value; } catch(e) {} } diff --git a/test/unit/css.js b/test/unit/css.js index 819a60c71..75237ed4e 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -970,6 +970,12 @@ test( ":visible/:hidden selectors", function() { t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] ); }); +test( "Override !important when changing styles (#14394)", function() { + expect( 1 ); + var el = jQuery( "
" ).css( "display", "none" ); + equal( el.css( "display" ), "none", "New style replaced !important" ); +}); + asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() { var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ), styles = [{ -- 2.39.5