var propName, attrNames, name, l,
i = 0;
- if ( value && typeof value === "string" && elem.nodeType === 1 ) {
- attrNames = jQuery.trim( value ).toLowerCase().split( " " );
+ if ( value && elem.nodeType === 1 ) {
+ attrNames = value.toLowerCase().split( rspace );
l = attrNames.length;
for ( ; i < l; i++ ) {
name = attrNames[ i ];
- propName = jQuery.propFix[ name ] || name;
- // See #9699 for explanation of this approach (setting first, then removal)
- jQuery.attr( elem, name, "" );
- elem.removeAttribute( getSetAttribute ? name : propName );
+ if ( name ) {
+ propName = jQuery.propFix[ name ] || name;
- // Set corresponding property to false for boolean attributes
- if ( rboolean.test( name ) && propName in elem ) {
- elem[ propName ] = false;
+ // See #9699 for explanation of this approach (setting first, then removal)
+ jQuery.attr( elem, name, "" );
+ elem.removeAttribute( getSetAttribute ? name : propName );
+
+ // Set corresponding property to false for boolean attributes
+ if ( rboolean.test( name ) && propName in elem ) {
+ elem[ propName ] = false;
+ }
}
}
}
}
});
-test("removeAttr, #", function() {
-
- var div = jQuery("<div />");
-
- ok( div.removeAttr( "" ), "empty string" );
- ok( div.removeAttr(), "nothing" );
- ok( div.removeAttr( false ), "false" );
- ok( div.removeAttr( true ), "true" );
- ok( div.removeAttr({ }), "object" );
- ok( div.removeAttr( function(){} ), "function" );
-
-});
-
-test("removeAttr(Multi String)", function() {
+test("removeAttr(Multi String, variable space width)", function() {
expect(8);
var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
equal( div.attr(key), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
});
- div.removeAttr( "id alt title rel " );
+ div.removeAttr( "id alt title rel " );
jQuery.each( tests, function( key, val ) {
equal( div.attr(key), undefined, "Attribute `" + key + "` was removed" );