aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes/val.js
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2016-03-15 18:15:02 -0400
committerTimmy Willison <timmywillisn@gmail.com>2016-03-17 12:24:51 -0400
commit70526981916945dc4093e116a3de61b1777d4718 (patch)
treecead432f2eb1bb6dee21ac161c7737d384e96a96 /src/attributes/val.js
parent055cb7534e2dcf7ee8ad145be83cb2d74b5331c7 (diff)
downloadjquery-70526981916945dc4093e116a3de61b1777d4718.tar.gz
jquery-70526981916945dc4093e116a3de61b1777d4718.zip
Attributes: strip/collapse whitespace for set values on selects
Fixes gh-2978 Close gh-3002
Diffstat (limited to 'src/attributes/val.js')
-rw-r--r--src/attributes/val.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/attributes/val.js b/src/attributes/val.js
index 5f0b73e00..a8a2e12fb 100644
--- a/src/attributes/val.js
+++ b/src/attributes/val.js
@@ -4,7 +4,8 @@ define( [
"../core/init"
], function( jQuery, support ) {
-var rreturn = /\r/g;
+var rreturn = /\r/g,
+ rspaces = /[\x20\t\r\n\f]+/g;
jQuery.fn.extend( {
val: function( value ) {
@@ -80,9 +81,15 @@ jQuery.extend( {
option: {
get: function( elem ) {
- // Support: IE<11
- // option.value not trimmed (#14858)
- return jQuery.trim( elem.value );
+ var val = jQuery.find.attr( elem, "value" );
+ return val != null ?
+ val :
+
+ // Support: IE10-11+
+ // option.text throws exceptions (#14686, #14858)
+ // Strip and collapse whitespace
+ // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
+ jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " );
}
},
select: {
@@ -134,7 +141,7 @@ jQuery.extend( {
while ( i-- ) {
option = options[ i ];
if ( option.selected =
- jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
+ jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
) {
optionSet = true;
}