diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-11 18:51:58 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-11 18:51:58 +0300 |
commit | 3f7cd73822007d63b6e2d07749900802107490b5 (patch) | |
tree | d7c5e2b53fed0115687da042f9fa55056a4fb644 | |
parent | 38261772a4054621b24135a5b2266eb2a12798b9 (diff) | |
download | jquery-3f7cd73822007d63b6e2d07749900802107490b5.tar.gz jquery-3f7cd73822007d63b6e2d07749900802107490b5.zip |
Revert "Attributes: do not set properties to false when removing booleans"
This reverts commit 47ccf3daadc4b312f850502300129952e70f9d9d.
-rw-r--r-- | src/attributes/attr.js | 12 | ||||
-rw-r--r-- | test/unit/attributes.js | 6 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/attributes/attr.js b/src/attributes/attr.js index ae48676d1..f88808324 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -86,12 +86,21 @@ 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 + elem[ propName ] = false; + } + elem.removeAttribute( name ); } } @@ -111,7 +120,6 @@ boolHook = { return name; } }; - jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) { var getter = attrHandle[ name ] || jQuery.find.attr; diff --git a/test/unit/attributes.js b/test/unit/attributes.js index b70022f9e..517c907db 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -564,7 +564,7 @@ QUnit.test( "attr('tabindex', value)", function( assert ) { } ); QUnit.test( "removeAttr(String)", function( assert ) { - assert.expect( 13 ); + assert.expect( 12 ); var $first; assert.equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" ); @@ -575,9 +575,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" ); - jQuery( "#option1b" ).attr( "selected", "selected" ).removeAttr( "selected" ).attr( "selected", "selected" ); - assert.notEqual( document.getElementById( "select1" ).selectedIndex, 1, "Once the selected attribute is dirty, subsequent settings should not select the option (gh-1759)" ); + 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" ); |