]> source.dussan.org Git - jquery.git/commitdiff
Landing pull request 492. 1.7 Remove multiple attributes (Symmetry with removeClass...
authorRick Waldron <waldron.rick@gmail.com>
Tue, 20 Sep 2011 01:07:07 +0000 (21:07 -0400)
committertimmywil <timmywillisn@gmail.com>
Tue, 20 Sep 2011 01:07:07 +0000 (21:07 -0400)
More Details:
 - https://github.com/jquery/jquery/pull/492
 - http://bugs.jquery.com/ticket/5479

src/attributes.js
test/unit/attributes.js

index 91b53f97e1933b9b5f4bbc388fba072650960b65..71353cf7875067bc4888ab705e6dbbb398f5b837 100644 (file)
@@ -362,18 +362,26 @@ jQuery.extend({
                }
        },
 
-       removeAttr: function( elem, name ) {
-               var propName;
+       removeAttr: function( elem, value ) {
+               var propName, attrNames, name, l,
+                       i = 0;
+
                if ( elem.nodeType === 1 ) {
-                       name = jQuery.attrFix[ name ] || name;
+                       attrNames = (value || "").split( rspace );
+                       l = attrNames.length;
 
-                       // See #9699 for explanation of this approach (setting first, then removal)
-                       jQuery.attr( elem, name, "" );
-                       elem.removeAttribute( name );
+                       for ( ; i < l; i++ ) {
+                               name = attrNames[ i ];
+                               name = jQuery.attrFix[ name ] || name;
 
-                       // Set corresponding property to false for boolean attributes
-                       if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) {
-                               elem[ propName ] = false;
+                               // See #9699 for explanation of this approach (setting first, then removal)
+                               jQuery.attr( elem, name, "" );
+                               elem.removeAttribute( name );
+
+                               // Set corresponding property to false for boolean attributes
+                               if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) {
+                                       elem[ propName ] = false;
+                               }
                        }
                }
        },
index 5945510de2039edfddd924fb994df558feea533f..da39933d3265972d8530c1edd3fef3094a6c5281 100644 (file)
@@ -532,6 +532,28 @@ test("prop(String, Object)", function() {
        jQuery( document ).removeProp("nonexisting");
 });
 
+test("removeAttr(Multi String)", function() {
+       expect(8);
+
+       var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
+               tests = {
+                       id: "a",
+                       alt: "b",
+                       title: "c",
+                       rel: "d"
+               };
+
+       jQuery.each( tests, function( key, val ) {
+               equal( div.attr(key), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
+       });
+
+       div.removeAttr( "id alt title rel" );
+
+       jQuery.each( tests, function( key, val ) {
+               equal( div.attr(key), undefined, "Attribute `" + key + "` was removed" );
+       });
+});
+
 test("prop('tabindex')", function() {
        expect(8);