Skip to content

Commit 0933a39

Browse files
authored
CSS: Don't break .css( array )
jQuery 1.9 added support for array input to the `.css()` method; so far Migrate was crashing with such input. Fixes jquerygh-357 Closes jquerygh-356
1 parent a19eabe commit 0933a39

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/jquery/css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ oldFnCss = jQuery.fn.css;
101101
jQuery.fn.css = function( name, value ) {
102102
var camelName,
103103
origThis = this;
104-
if ( typeof name !== "string" ) {
104+
if ( name && typeof name === "object" && !Array.isArray( name ) ) {
105105
jQuery.each( name, function( n, v ) {
106106
jQuery.fn.css.call( origThis, n, v );
107107
} );

test/css.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ QUnit[ ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) ? "test
4444
delete jQuery.cssProps.devoHat;
4545
} );
4646

47+
QUnit.test( "jQuery.css with arrays", function( assert ) {
48+
assert.expect( 2 );
49+
50+
expectNoWarning( assert, "String value direct", function() {
51+
var cssValues = jQuery( "<div />" )
52+
.css( {
53+
lineHeight: "1",
54+
fontSize: "16px"
55+
} )
56+
.css( [ "font-size", "lineHeight" ] );
57+
58+
assert.deepEqual( cssValues, { "font-size": "16px", lineHeight: "1" },
59+
".css( array ) works" );
60+
} );
61+
} );
62+
4763
QUnit.test( "jQuery.css with numbers", function( assert ) {
4864
var jQuery3OrOlder = compareVersions( jQuery.fn.jquery, "4.0.0" ) < 0,
4965
whitelist = [

0 commit comments

Comments
 (0)