Skip to content

Commit aec41a5

Browse files
committed
Attributes: Simplify the option val hook; backport a test from master
The hook is still defined; not using it could cause issues in IE<11. Backport the test from the master branch. Also, IE10 no longer throws when value not set but it still doesn't trim the value. IE11 has all those issues fixed; support comments are updated. (cherry-picked from f6302b0) Fixes gh-1902 Closes gh-1901
1 parent 90d7cc1 commit aec41a5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/attributes/val.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@ jQuery.extend({
7272
valHooks: {
7373
option: {
7474
get: function( elem ) {
75-
var val = jQuery.find.attr( elem, "value" );
76-
return val != null ?
77-
val :
78-
// Support: IE10-11+
79-
// option.text throws exceptions (#14686, #14858)
80-
jQuery.trim( jQuery.text( elem ) );
75+
// Support: IE<11
76+
// option.value not trimmed (#14858)
77+
return jQuery.trim( elem.value );
8178
}
8279
},
8380
select: {

test/unit/attributes.js

+5
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,11 @@ test( "should not throw at $(option).val() (#14686)", 1, function() {
14591459
}
14601460
});
14611461

1462+
test( "option value not trimmed when setting via parent select", function() {
1463+
expect( 1 );
1464+
equal( jQuery( "<select><option> 2</option></select>" ).val( "2" ).val(), "2" );
1465+
});
1466+
14621467
test( "Insignificant white space returned for $(option).val() (#14858)", function() {
14631468
expect ( 3 );
14641469

0 commit comments

Comments
 (0)