Skip to content

Commit 3f7cd73

Browse files
committed
Revert "Attributes: do not set properties to false when removing booleans"
This reverts commit 47ccf3d.
1 parent 3826177 commit 3f7cd73

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/attributes/attr.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,21 @@ jQuery.extend( {
8686
},
8787

8888
removeAttr: function( elem, value ) {
89-
var name,
89+
var name, propName,
9090
i = 0,
9191
attrNames = value && value.match( rnotwhite );
9292

9393
if ( attrNames && elem.nodeType === 1 ) {
9494
while ( ( name = attrNames[ i++ ] ) ) {
95+
propName = jQuery.propFix[ name ] || name;
96+
97+
// Boolean attributes get special treatment (#10870)
98+
if ( jQuery.expr.match.bool.test( name ) ) {
99+
100+
// Set corresponding property to false
101+
elem[ propName ] = false;
102+
}
103+
95104
elem.removeAttribute( name );
96105
}
97106
}
@@ -111,7 +120,6 @@ boolHook = {
111120
return name;
112121
}
113122
};
114-
115123
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
116124
var getter = attrHandle[ name ] || jQuery.find.attr;
117125

test/unit/attributes.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ QUnit.test( "attr('tabindex', value)", function( assert ) {
564564
} );
565565

566566
QUnit.test( "removeAttr(String)", function( assert ) {
567-
assert.expect( 13 );
567+
assert.expect( 12 );
568568
var $first;
569569

570570
assert.equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" );
@@ -575,9 +575,7 @@ QUnit.test( "removeAttr(String)", function( assert ) {
575575
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" );
576576

577577
jQuery( "#check1" ).removeAttr( "checked" ).prop( "checked", true ).removeAttr( "checked" );
578-
assert.equal( document.getElementById( "check1" ).checked, true, "removeAttr should not set checked to false, since the checked attribute does NOT mirror the checked property" );
579-
jQuery( "#option1b" ).attr( "selected", "selected" ).removeAttr( "selected" ).attr( "selected", "selected" );
580-
assert.notEqual( document.getElementById( "select1" ).selectedIndex, 1, "Once the selected attribute is dirty, subsequent settings should not select the option (gh-1759)" );
578+
assert.equal( document.getElementById( "check1" ).checked, false, "removeAttr sets boolean properties to false" );
581579
jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" );
582580
assert.equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" );
583581

0 commit comments

Comments
 (0)