3 "../core/stripAndCollapse",
9 ], function( jQuery, stripAndCollapse, support, nodeName, isFunction ) {
16 val: function( value ) {
17 var hooks, ret, valueIsFunction,
20 if ( !arguments.length ) {
22 hooks = jQuery.valHooks[ elem.type ] ||
23 jQuery.valHooks[ elem.nodeName.toLowerCase() ];
27 ( ret = hooks.get( elem, "value" ) ) !== undefined
34 // Handle most common string cases
35 if ( typeof ret === "string" ) {
36 return ret.replace( rreturn, "" );
39 // Handle cases where value is null/undef or number
40 return ret == null ? "" : ret;
46 valueIsFunction = isFunction( value );
48 return this.each( function( i ) {
51 if ( this.nodeType !== 1 ) {
55 if ( valueIsFunction ) {
56 val = value.call( this, i, jQuery( this ).val() );
61 // Treat null/undefined as ""; convert numbers to string
65 } else if ( typeof val === "number" ) {
68 } else if ( Array.isArray( val ) ) {
69 val = jQuery.map( val, function( value ) {
70 return value == null ? "" : value + "";
74 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
76 // If set returns undefined, fall back to normal setting
77 if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
87 get: function( elem ) {
89 var val = jQuery.find.attr( elem, "value" );
93 // Support: IE <=10 - 11 only
94 // option.text throws exceptions (#14686, #14858)
95 // Strip and collapse whitespace
96 // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
97 stripAndCollapse( jQuery.text( elem ) );
101 get: function( elem ) {
102 var value, option, i,
103 options = elem.options,
104 index = elem.selectedIndex,
105 one = elem.type === "select-one",
106 values = one ? null : [],
107 max = one ? index + 1 : options.length;
116 // Loop through all the selected options
117 for ( ; i < max; i++ ) {
118 option = options[ i ];
120 // Support: IE <=9 only
121 // IE8-9 doesn't update selected after form reset (#2551)
122 if ( ( option.selected || i === index ) &&
124 // Don't return options that are disabled or in a disabled optgroup
126 ( !option.parentNode.disabled ||
127 !nodeName( option.parentNode, "optgroup" ) ) ) {
129 // Get the specific value for the option
130 value = jQuery( option ).val();
132 // We don't need an array for one selects
137 // Multi-Selects return an array
138 values.push( value );
145 set: function( elem, value ) {
146 var optionSet, option,
147 options = elem.options,
148 values = jQuery.makeArray( value ),
152 option = options[ i ];
154 /* eslint-disable no-cond-assign */
156 if ( option.selected =
157 jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
162 /* eslint-enable no-cond-assign */
165 // Force browsers to behave consistently when non-matching value is set
167 elem.selectedIndex = -1;
175 // Radios and checkboxes getter/setter
176 jQuery.each( [ "radio", "checkbox" ], function() {
177 jQuery.valHooks[ this ] = {
178 set: function( elem, value ) {
179 if ( Array.isArray( value ) ) {
180 return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
184 if ( !support.checkOn ) {
185 jQuery.valHooks[ this ].get = function( elem ) {
186 return elem.getAttribute( "value" ) === null ? "on" : elem.value;