8 ], function( jQuery, rnotwhite, strundefined, access, support ) {
10 var nodeHook, boolHook,
11 attrHandle = jQuery.expr.attrHandle;
14 attr: function( name, value ) {
15 return access( this, jQuery.attr, name, value, arguments.length > 1 );
18 removeAttr: function( name ) {
19 return this.each(function() {
20 jQuery.removeAttr( this, name );
26 attr: function( elem, name, value ) {
28 nType = elem.nodeType;
30 // don't get/set attributes on text, comment and attribute nodes
31 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
35 // Fallback to prop when attributes are not supported
36 if ( typeof elem.getAttribute === strundefined ) {
37 return jQuery.prop( elem, name, value );
40 // All attributes are lowercase
41 // Grab necessary hook if one is defined
42 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
43 name = name.toLowerCase();
44 hooks = jQuery.attrHooks[ name ] ||
45 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
48 if ( value !== undefined ) {
50 if ( value === null ) {
51 jQuery.removeAttr( elem, name );
53 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
57 elem.setAttribute( name, value + "" );
61 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
65 ret = jQuery.find.attr( elem, name );
67 // Non-existent attributes return null, we normalize to undefined
74 removeAttr: function( elem, value ) {
77 attrNames = value && value.match( rnotwhite );
79 if ( attrNames && elem.nodeType === 1 ) {
80 while ( (name = attrNames[i++]) ) {
81 propName = jQuery.propFix[ name ] || name;
83 // Boolean attributes get special treatment (#10870)
84 if ( jQuery.expr.match.bool.test( name ) ) {
85 // Set corresponding property to false
86 elem[ propName ] = false;
89 elem.removeAttribute( name );
96 set: function( elem, value ) {
97 if ( !support.radioValue && value === "radio" &&
98 jQuery.nodeName( elem, "input" ) ) {
100 elem.setAttribute( "type", value );
111 // Hooks for boolean attributes
113 set: function( elem, value, name ) {
114 if ( value === false ) {
115 // Remove boolean attributes when set to false
116 jQuery.removeAttr( elem, name );
118 elem.setAttribute( name, name );
123 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
124 var getter = attrHandle[ name ] || jQuery.find.attr;
126 attrHandle[ name ] = function( elem, name, isXML ) {
129 // Avoid an infinite loop by temporarily removing this function from the getter
130 handle = attrHandle[ name ];
131 attrHandle[ name ] = ret;
132 ret = getter( elem, name, isXML ) != null ?
135 attrHandle[ name ] = handle;