5 ], function( jQuery, support ) {
10 val: function( value ) {
11 var hooks, ret, isFunction,
14 if ( !arguments.length ) {
16 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
18 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
24 return typeof ret === "string" ?
25 // Handle most common string cases
26 ret.replace(rreturn, "") :
27 // Handle cases where value is null/undef or number
28 ret == null ? "" : ret;
34 isFunction = jQuery.isFunction( value );
36 return this.each(function( i ) {
39 if ( this.nodeType !== 1 ) {
44 val = value.call( this, i, jQuery( this ).val() );
49 // Treat null/undefined as ""; convert numbers to string
53 } else if ( typeof val === "number" ) {
56 } else if ( jQuery.isArray( val ) ) {
57 val = jQuery.map( val, function( value ) {
58 return value == null ? "" : value + "";
62 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
64 // If set returns undefined, fall back to normal setting
65 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
75 get: function( elem ) {
76 var val = jQuery.find.attr( elem, "value" );
80 // option.text throws exceptions (#14686, #14858)
81 jQuery.trim( jQuery.text( elem ) );
85 get: function( elem ) {
87 options = elem.options,
88 index = elem.selectedIndex,
89 one = elem.type === "select-one" || index < 0,
90 values = one ? null : [],
91 max = one ? index + 1 : options.length,
96 // Loop through all the selected options
97 for ( ; i < max; i++ ) {
98 option = options[ i ];
100 // IE6-9 doesn't update selected after form reset (#2551)
101 if ( ( option.selected || i === index ) &&
102 // Don't return options that are disabled or in a disabled optgroup
103 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
104 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
106 // Get the specific value for the option
107 value = jQuery( option ).val();
109 // We don't need an array for one selects
114 // Multi-Selects return an array
115 values.push( value );
122 set: function( elem, value ) {
123 var optionSet, option,
124 options = elem.options,
125 values = jQuery.makeArray( value ),
129 option = options[ i ];
130 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
135 // Force browsers to behave consistently when non-matching value is set
137 elem.selectedIndex = -1;
145 // Radios and checkboxes getter/setter
146 jQuery.each([ "radio", "checkbox" ], function() {
147 jQuery.valHooks[ this ] = {
148 set: function( elem, value ) {
149 if ( jQuery.isArray( value ) ) {
150 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
154 if ( !support.checkOn ) {
155 jQuery.valHooks[ this ].get = function( elem ) {
156 return elem.getAttribute("value") === null ? "on" : elem.value;