Commit ca4133cc authored by Rick Waldron's avatar Rick Waldron Committed by timmywil

Landing pull request 492. 1.7 Remove multiple attributes (Symmetry with...

Landing pull request 492. 1.7 Remove multiple attributes (Symmetry with removeClass) Combines patches submitted by leeoniya, zertosh and my own tests. Fixes #5479.

More Details:
 - https://github.com/jquery/jquery/pull/492
 - http://bugs.jquery.com/ticket/5479
parent f6021364
...@@ -362,18 +362,26 @@ jQuery.extend({ ...@@ -362,18 +362,26 @@ jQuery.extend({
} }
}, },
removeAttr: function( elem, name ) { removeAttr: function( elem, value ) {
var propName; var propName, attrNames, name, l,
i = 0;
if ( elem.nodeType === 1 ) { 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) for ( ; i < l; i++ ) {
jQuery.attr( elem, name, "" ); name = attrNames[ i ];
elem.removeAttribute( name ); name = jQuery.attrFix[ name ] || name;
// Set corresponding property to false for boolean attributes // See #9699 for explanation of this approach (setting first, then removal)
if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) { jQuery.attr( elem, name, "" );
elem[ propName ] = false; 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;
}
} }
} }
}, },
......
...@@ -532,6 +532,28 @@ test("prop(String, Object)", function() { ...@@ -532,6 +532,28 @@ test("prop(String, Object)", function() {
jQuery( document ).removeProp("nonexisting"); 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() { test("prop('tabindex')", function() {
expect(8); expect(8);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment