1 var nodeHook, boolHook,
4 rfocusable = /^(?:input|select|textarea|button|object)$/i,
5 rclickable = /^(?:a|area)$/i;
8 attr: function( name, value ) {
9 return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
12 removeAttr: function( name ) {
13 return this.each(function() {
14 jQuery.removeAttr( this, name );
18 prop: function( name, value ) {
19 return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 );
22 removeProp: function( name ) {
23 return this.each(function() {
24 delete this[ jQuery.propFix[ name ] || name ];
28 addClass: function( value ) {
29 var classes, elem, cur, clazz, j,
32 proceed = typeof value === "string" && value;
34 if ( jQuery.isFunction( value ) ) {
35 return this.each(function( j ) {
36 jQuery( this ).addClass( value.call( this, j, this.className ) );
41 // The disjunction here is for better compressibility (see removeClass)
42 classes = ( value || "" ).match( core_rnotwhite ) || [];
44 for ( ; i < len; i++ ) {
46 cur = elem.nodeType === 1 && ( elem.className ?
47 ( " " + elem.className + " " ).replace( rclass, " " ) :
53 while ( (clazz = classes[j++]) ) {
54 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
58 elem.className = jQuery.trim( cur );
67 removeClass: function( value ) {
68 var classes, elem, cur, clazz, j,
71 proceed = arguments.length === 0 || typeof value === "string" && value;
73 if ( jQuery.isFunction( value ) ) {
74 return this.each(function( j ) {
75 jQuery( this ).removeClass( value.call( this, j, this.className ) );
79 classes = ( value || "" ).match( core_rnotwhite ) || [];
81 for ( ; i < len; i++ ) {
83 // This expression is here for better compressibility (see addClass)
84 cur = elem.nodeType === 1 && ( elem.className ?
85 ( " " + elem.className + " " ).replace( rclass, " " ) :
91 while ( (clazz = classes[j++]) ) {
92 // Remove *all* instances
93 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
94 cur = cur.replace( " " + clazz + " ", " " );
97 elem.className = value ? jQuery.trim( cur ) : "";
105 toggleClass: function( value, stateVal ) {
106 var type = typeof value,
107 isBool = typeof stateVal === "boolean";
109 if ( jQuery.isFunction( value ) ) {
110 return this.each(function( i ) {
111 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
115 return this.each(function() {
116 if ( type === "string" ) {
117 // toggle individual class names
120 self = jQuery( this ),
122 classNames = value.match( core_rnotwhite ) || [];
124 while ( (className = classNames[ i++ ]) ) {
125 // check each className given, space separated list
126 state = isBool ? state : !self.hasClass( className );
127 self[ state ? "addClass" : "removeClass" ]( className );
130 // Toggle whole class name
131 } else if ( type === core_strundefined || type === "boolean" ) {
132 if ( this.className ) {
133 // store className if set
134 data_priv.set( this, "__className__", this.className );
137 // If the element has a class name or if we're passed "false",
138 // then remove the whole classname (if there was one, the above saved it).
139 // Otherwise bring back whatever was previously saved (if anything),
140 // falling back to the empty string if nothing was stored.
141 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
146 hasClass: function( selector ) {
147 var className = " " + selector + " ",
150 for ( ; i < l; i++ ) {
151 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
159 val: function( value ) {
160 var hooks, ret, isFunction,
163 if ( !arguments.length ) {
165 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
167 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
173 return typeof ret === "string" ?
174 // handle most common string cases
175 ret.replace(rreturn, "") :
176 // handle cases where value is null/undef or number
177 ret == null ? "" : ret;
183 isFunction = jQuery.isFunction( value );
185 return this.each(function( i ) {
189 if ( this.nodeType !== 1 ) {
194 val = value.call( this, i, self.val() );
199 // Treat null/undefined as ""; convert numbers to string
202 } else if ( typeof val === "number" ) {
204 } else if ( jQuery.isArray( val ) ) {
205 val = jQuery.map(val, function ( value ) {
206 return value == null ? "" : value + "";
210 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
212 // If set returns undefined, fall back to normal setting
213 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
223 get: function( elem ) {
224 // attributes.value is undefined in Blackberry 4.7 but
225 // uses .value. See #6932
226 var val = elem.attributes.value;
227 return !val || val.specified ? elem.value : elem.text;
231 get: function( elem ) {
233 options = elem.options,
234 index = elem.selectedIndex,
235 one = elem.type === "select-one" || index < 0,
236 values = one ? null : [],
237 max = one ? index + 1 : options.length,
242 // Loop through all the selected options
243 for ( ; i < max; i++ ) {
244 option = options[ i ];
246 // IE6-9 doesn't update selected after form reset (#2551)
247 if ( ( option.selected || i === index ) &&
248 // Don't return options that are disabled or in a disabled optgroup
249 ( jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) &&
250 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
252 // Get the specific value for the option
253 value = jQuery( option ).val();
255 // We don't need an array for one selects
260 // Multi-Selects return an array
261 values.push( value );
268 set: function( elem, value ) {
269 var optionSet, option,
270 options = elem.options,
271 values = jQuery.makeArray( value ),
275 option = options[ i ];
276 if ( (option.selected = jQuery.inArray( jQuery(option).val(), values ) >= 0) ) {
281 // force browsers to behave consistently when non-matching value is set
283 elem.selectedIndex = -1;
290 attr: function( elem, name, value ) {
292 nType = elem.nodeType;
294 // don't get/set attributes on text, comment and attribute nodes
295 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
299 // Fallback to prop when attributes are not supported
300 if ( typeof elem.getAttribute === core_strundefined ) {
301 return jQuery.prop( elem, name, value );
304 // All attributes are lowercase
305 // Grab necessary hook if one is defined
306 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
307 name = name.toLowerCase();
308 hooks = jQuery.attrHooks[ name ] ||
309 ( jQuery.expr.match.boolean.test( name ) ? boolHook : nodeHook );
312 if ( value !== undefined ) {
314 if ( value === null ) {
315 jQuery.removeAttr( elem, name );
317 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
321 elem.setAttribute( name, value + "" );
325 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
329 ret = jQuery.find.attr( elem, name );
331 // Non-existent attributes return null, we normalize to undefined
338 removeAttr: function( elem, value ) {
341 attrNames = value && value.match( core_rnotwhite );
343 if ( attrNames && elem.nodeType === 1 ) {
344 while ( (name = attrNames[i++]) ) {
345 propName = jQuery.propFix[ name ] || name;
347 // Boolean attributes get special treatment (#10870)
348 if ( jQuery.expr.match.boolean.test( name ) ) {
349 // Set corresponding property to false
350 elem[ propName ] = false;
353 elem.removeAttribute( name );
360 set: function( elem, value ) {
361 if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
362 // Setting the type on a radio button after the value resets the value in IE6-9
363 // Reset value to default in case type is set after value during creation
364 var val = elem.value;
365 elem.setAttribute( "type", value );
380 prop: function( elem, name, value ) {
381 var ret, hooks, notxml,
382 nType = elem.nodeType;
384 // don't get/set properties on text, comment and attribute nodes
385 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
389 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
392 // Fix name and attach hooks
393 name = jQuery.propFix[ name ] || name;
394 hooks = jQuery.propHooks[ name ];
397 if ( value !== undefined ) {
398 if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
402 return ( elem[ name ] = value );
406 if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
417 get: function( elem ) {
418 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
419 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
420 var attributeNode = elem.getAttributeNode("tabindex");
422 return attributeNode && attributeNode.specified ?
423 parseInt( attributeNode.value, 10 ) :
424 rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
432 // Hooks for boolean attributes
434 set: function( elem, value, name ) {
435 if ( value === false ) {
436 // Remove boolean attributes when set to false
437 jQuery.removeAttr( elem, name );
439 elem.setAttribute( name, name );
444 jQuery.each( jQuery.expr.match.boolean.source.match( /\w+/g ), function( i, name ) {
445 var getter = jQuery.expr.attrHandle[ name ] || jQuery.find.attr;
447 jQuery.expr.attrHandle[ name ] = function( elem, name, isXML ) {
448 var fn = jQuery.expr.attrHandle[ name ],
451 /* jshint eqeqeq: false */
452 // Temporarily disable this handler to check existence
453 (jQuery.expr.attrHandle[ name ] = undefined) !=
454 getter( elem, name, isXML ) ?
460 jQuery.expr.attrHandle[ name ] = fn;
467 // Selectedness for an option in an optgroup can be inaccurate
468 if ( !jQuery.support.optSelected ) {
469 jQuery.propHooks.selected = {
470 get: function( elem ) {
471 var parent = elem.parentNode;
472 if ( parent && parent.parentNode ) {
473 parent.parentNode.selectedIndex;
492 jQuery.propFix[ this.toLowerCase() ] = this;
495 // Radios and checkboxes getter/setter
496 jQuery.each([ "radio", "checkbox" ], function() {
497 jQuery.valHooks[ this ] = {
498 set: function( elem, value ) {
499 if ( jQuery.isArray( value ) ) {
500 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
504 if ( !jQuery.support.checkOn ) {
505 jQuery.valHooks[ this ].get = function( elem ) {
507 // "" is returned instead of "on" if a value isn't specified
508 return elem.getAttribute("value") === null ? "on" : elem.value;