diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 22945c255..125e094d9 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -92,12 +92,29 @@ jQuery.extend( { }, removeAttr: function( elem, value ) { - var name, + var name, propName, i = 0, attrNames = value && value.match( rnotwhite ); if ( attrNames && elem.nodeType === 1 ) { while ( ( name = attrNames[ i++ ] ) ) { + propName = jQuery.propFix[ name ] || name; + + // Boolean attributes get special treatment (#10870) + if ( jQuery.expr.match.bool.test( name ) ) { + + // Set corresponding property to false + if ( getSetInput || !ruseDefault.test( name ) ) { + elem[ propName ] = false; + + // Support: IE<9 + // Also clear defaultChecked/defaultSelected (if appropriate) + } else { + elem[ jQuery.camelCase( "default-" + name ) ] = + elem[ propName ] = false; + } + } + elem.removeAttribute( name ); } } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index d5826566f..6a8f3acfc 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -574,7 +574,7 @@ QUnit.test( "removeAttr(String)", function( assert ) { assert.equal( jQuery( "#fx-test-group" ).attr( "height", "3px" ).removeAttr( "height" ).get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" ); jQuery( "#check1" ).removeAttr( "checked" ).prop( "checked", true ).removeAttr( "checked" ); - assert.equal( document.getElementById( "check1" ).checked, true, "removeAttr should not set checked to false, since the checked attribute does NOT mirror the checked property" ); + assert.equal( document.getElementById( "check1" ).checked, false, "removeAttr sets boolean properties to false" ); jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" ); assert.equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" );