aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes/val.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/attributes/val.js')
-rw-r--r--src/attributes/val.js41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/attributes/val.js b/src/attributes/val.js
index 38e170ba8..f200f97ee 100644
--- a/src/attributes/val.js
+++ b/src/attributes/val.js
@@ -1,11 +1,10 @@
import jQuery from "../core.js";
+import isIE from "../var/isIE.js";
import stripAndCollapse from "../core/stripAndCollapse.js";
import nodeName from "../core/nodeName.js";
import "../core/init.js";
-var rreturn = /\r/g;
-
jQuery.fn.extend( {
val: function( value ) {
var hooks, ret, valueIsFunction,
@@ -25,11 +24,6 @@ jQuery.fn.extend( {
ret = elem.value;
- // Handle most common string cases
- if ( typeof ret === "string" ) {
- return ret.replace( rreturn, "" );
- }
-
// Handle cases where value is null/undef or number
return ret == null ? "" : ret;
}
@@ -77,20 +71,6 @@ jQuery.fn.extend( {
jQuery.extend( {
valHooks: {
- option: {
- get: function( elem ) {
-
- var val = elem.getAttribute( "value" );
- return val != null ?
- val :
-
- // Support: IE <=10 - 11+
- // option.text throws exceptions (#14686, #14858)
- // Strip and collapse whitespace
- // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
- stripAndCollapse( jQuery.text( elem ) );
- }
- },
select: {
get: function( elem ) {
var value, option, i,
@@ -144,7 +124,7 @@ jQuery.extend( {
option = options[ i ];
if ( ( option.selected =
- jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
+ jQuery.inArray( jQuery( option ).val(), values ) > -1
) ) {
optionSet = true;
}
@@ -160,6 +140,23 @@ jQuery.extend( {
}
} );
+if ( isIE ) {
+ jQuery.valHooks.option = {
+ get: function( elem ) {
+
+ var val = elem.getAttribute( "value" );
+ return val != null ?
+ val :
+
+ // Support: IE <=10 - 11+
+ // option.text throws exceptions (#14686, #14858)
+ // Strip and collapse whitespace
+ // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
+ stripAndCollapse( jQuery.text( elem ) );
+ }
+ };
+}
+
// Radios and checkboxes getter/setter
jQuery.each( [ "radio", "checkbox" ], function() {
jQuery.valHooks[ this ] = {