7 ], function( jQuery, rnotwhite, access, support ) {
9 var nodeHook, boolHook,
10 attrHandle = jQuery.expr.attrHandle;
13 attr: function( name, value ) {
14 return access( this, jQuery.attr, name, value, arguments.length > 1 );
17 removeAttr: function( name ) {
18 return this.each(function() {
19 jQuery.removeAttr( this, name );
25 attr: function( elem, name, value ) {
27 nType = elem.nodeType;
29 // don't get/set attributes on text, comment and attribute nodes
30 if ( nType === 3 || nType === 8 || nType === 2 ) {
34 // Fallback to prop when attributes are not supported
35 if ( typeof elem.getAttribute === "undefined" ) {
36 return jQuery.prop( elem, name, value );
39 // All attributes are lowercase
40 // Grab necessary hook if one is defined
41 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
42 name = name.toLowerCase();
43 hooks = jQuery.attrHooks[ name ] ||
44 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
47 if ( value !== undefined ) {
49 if ( value === null ) {
50 jQuery.removeAttr( elem, name );
52 } else if ( hooks && "set" in hooks &&
53 (ret = hooks.set( elem, value, name )) !== undefined ) {
58 elem.setAttribute( name, value + "" );
62 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
66 ret = jQuery.find.attr( elem, name );
68 // Non-existent attributes return null, we normalize to undefined
75 removeAttr: function( elem, value ) {
78 attrNames = value && value.match( rnotwhite );
80 if ( attrNames && elem.nodeType === 1 ) {
81 while ( (name = attrNames[i++]) ) {
82 propName = jQuery.propFix[ name ] || name;
84 // Boolean attributes get special treatment (#10870)
85 if ( jQuery.expr.match.bool.test( name ) ) {
86 // Set corresponding property to false
87 elem[ propName ] = false;
90 elem.removeAttribute( name );
97 set: function( elem, value ) {
98 if ( !support.radioValue && value === "radio" &&
99 jQuery.nodeName( elem, "input" ) ) {
100 var val = elem.value;
101 elem.setAttribute( "type", value );
112 // Hooks for boolean attributes
114 set: function( elem, value, name ) {
115 if ( value === false ) {
116 // Remove boolean attributes when set to false
117 jQuery.removeAttr( elem, name );
119 elem.setAttribute( name, name );
124 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
125 var getter = attrHandle[ name ] || jQuery.find.attr;
127 attrHandle[ name ] = function( elem, name, isXML ) {
130 // Avoid an infinite loop by temporarily removing this function from the getter
131 handle = attrHandle[ name ];
132 attrHandle[ name ] = ret;
133 ret = getter( elem, name, isXML ) != null ?
136 attrHandle[ name ] = handle;