]> source.dussan.org Git - jquery.git/commitdiff
Attributes: do not set properties to false when removing booleans 2665/head
authorTimmy Willison <timmywillisn@gmail.com>
Sun, 18 Oct 2015 21:21:41 +0000 (17:21 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Wed, 21 Oct 2015 20:23:44 +0000 (16:23 -0400)
Fixes gh-1759

src/attributes/attr.js
test/unit/attributes.js

index f88808324d7fa00672be1bd48172d51769c421c1..ae48676d1f2d58ec078fe4dfb0523e2d2515d1ef 100644 (file)
@@ -86,21 +86,12 @@ jQuery.extend( {
        },
 
        removeAttr: function( elem, value ) {
-               var name, propName,
+               var name,
                        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 );
                        }
                }
@@ -120,6 +111,7 @@ boolHook = {
                return name;
        }
 };
+
 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
        var getter = attrHandle[ name ] || jQuery.find.attr;
 
index 564fb12e071e1bf84236156a2a393db6e72f35e2..c1e159b8f073b4212dd04d3ed3807559c70c4332 100644 (file)
@@ -564,7 +564,7 @@ QUnit.test( "attr('tabindex', value)", function( assert ) {
 } );
 
 QUnit.test( "removeAttr(String)", function( assert ) {
-       assert.expect( 12 );
+       assert.expect( 13 );
        var $first;
 
        assert.equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" );
@@ -575,7 +575,9 @@ 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, false, "removeAttr sets boolean properties to false" );
+       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)" );
        jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" );
        assert.equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" );