diff --git a/src/attributes/val.js b/src/attributes/val.js index caf0126d4..5f0b73e00 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -90,7 +90,7 @@ jQuery.extend( { var value, option, options = elem.options, index = elem.selectedIndex, - one = elem.type === "select-one" || index < 0, + one = elem.type === "select-one", values = one ? null : [], max = one ? index + 1 : options.length, i = index < 0 ? diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 9ea29a105..9bf287688 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -903,10 +903,10 @@ QUnit.test( "val() with non-matching values on dropdown list", function( assert var select6 = jQuery( "" ).appendTo( "#form" ); jQuery( select6 ).val( "nothing" ); - assert.equal( jQuery( select6 ).val(), null, "Non-matching set (single value) on select-multiple" ); + assert.deepEqual( jQuery( select6 ).val(), [], "Non-matching set (single value) on select-multiple" ); jQuery( select6 ).val( [ "nothing1", "nothing2" ] ); - assert.equal( jQuery( select6 ).val(), null, "Non-matching set (array of values) on select-multiple" ); + assert.deepEqual( jQuery( select6 ).val(), [], "Non-matching set (array of values) on select-multiple" ); select6.remove(); } );