Skip to content

Commit 47ccf3d

Browse files
committed
Attributes: do not set properties to false when removing booleans
Fixes gh-1759
1 parent 15ac848 commit 47ccf3d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/attributes/attr.js

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

8888
removeAttr: function( elem, value ) {
89-
var name, propName,
89+
var name,
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-
10495
elem.removeAttribute( name );
10596
}
10697
}
@@ -120,6 +111,7 @@ boolHook = {
120111
return name;
121112
}
122113
};
114+
123115
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
124116
var getter = attrHandle[ name ] || jQuery.find.attr;
125117

test/unit/attributes.js

Lines changed: 4 additions & 2 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( 12 );
567+
assert.expect( 13 );
568568
var $first;
569569

570570
assert.equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" );
@@ -575,7 +575,9 @@ 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, false, "removeAttr sets boolean properties to false" );
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)" );
579581
jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" );
580582
assert.equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" );
581583

0 commit comments

Comments
 (0)