diff options
author | John Resig <jeresig@gmail.com> | 2010-09-28 08:53:09 -0700 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2010-09-28 08:53:09 -0700 |
commit | 558d96b42aab634e26a66ff337a03ae89be5b33b (patch) | |
tree | 529a31b9793a1490534f9c16b7948c1d1cdf3f5d | |
parent | 879799fe955f01b85b59fd8a0096d415fc48df03 (diff) | |
download | jquery-558d96b42aab634e26a66ff337a03ae89be5b33b.tar.gz jquery-558d96b42aab634e26a66ff337a03ae89be5b33b.zip |
Make setting .css(name, undefined) a no-op. Fixes #4388.
-rw-r--r-- | src/css.js | 5 | ||||
-rw-r--r-- | test/unit/css.js | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/css.js b/src/css.js index 07ff686d0..61cdc48f9 100644 --- a/src/css.js +++ b/src/css.js @@ -20,6 +20,11 @@ var ralpha = /alpha\([^)]*\)/, }; jQuery.fn.css = function( name, value ) { + // Setting 'undefined' is a no-op + if ( arguments.length === 2 && value === undefined ) { + return this; + } + return jQuery.access( this, name, value, true, function( elem, name, value ) { return value !== undefined ? jQuery.style( elem, name, value ) : diff --git a/test/unit/css.js b/test/unit/css.js index 0e91ae159..24aba794b 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -64,7 +64,8 @@ test("css(String|Hash)", function() { }); test("css(String, Object)", function() { - expect(19); + expect(21); + ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible'); jQuery('#nothiddendiv').css("display", 'none'); ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden'); @@ -96,6 +97,13 @@ test("css(String, Object)", function() { // opera sometimes doesn't update 'display' correctly, see #2037 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" ); + + var div = jQuery("#nothiddendiv"), + display = div.css("display"), + ret = div.css("display", undefined); + + equals( ret, div, "Make sure setting undefined returns the original set." ); + equals( div.css("display"), display, "Make sure that the display wasn't changed." ); }); if(jQuery.browser.msie) { |