]> source.dussan.org Git - jquery.git/commitdiff
Fix #14394: Changing style !important in webkit. Close gh-1385.
authorLihan Li <frankieteardrop@gmail.com>
Sun, 29 Sep 2013 16:06:32 +0000 (12:06 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Tue, 15 Oct 2013 20:38:38 +0000 (16:38 -0400)
(cherry picked from commit 24e587929f62428e1959b10aace6dc4fd65ab397)

Conflicts:

src/css.js

src/css.js
test/unit/css.js

index 09d7891684b53e21d1be27907f54f5ea6d8b8ce0..b18f8220212630f757a4d53add90d0141a237ea1 100644 (file)
@@ -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) {}
                        }
index 819a60c719f5b4d1be60c9fcfaa519cef4ff26ad..75237ed4e96f91f088bd08f0c64adc94c6afa7aa 100644 (file)
@@ -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( "<div style='display: block !important;'></div>" ).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 = [{