aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2015-10-18 17:21:41 -0400
committerRichard Gibson <richard.gibson@gmail.com>2015-10-26 16:08:49 -0400
commit5c086c3782459307c44397549fef15a87c8b90c4 (patch)
treef41fb4484bc281ee03cb7ee4320e70ec5c197fcf
parenta93d1d7d78a38be8d2c40d615f56f823c660e0ae (diff)
downloadjquery-5c086c3782459307c44397549fef15a87c8b90c4.tar.gz
jquery-5c086c3782459307c44397549fef15a87c8b90c4.zip
Attributes: do not set properties to false when removing booleans
Fixes gh-1759 (cherry picked from commit 47ccf3daadc4b312f850502300129952e70f9d9d) Conflicts: src/attributes/attr.js
-rw-r--r--src/attributes/attr.js19
-rw-r--r--test/unit/attributes.js6
2 files changed, 5 insertions, 20 deletions
diff --git a/src/attributes/attr.js b/src/attributes/attr.js
index 125e094d9..22945c255 100644
--- a/src/attributes/attr.js
+++ b/src/attributes/attr.js
@@ -92,29 +92,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
- 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 6a8f3acfc..79b191663 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -563,7 +563,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" );
@@ -574,7 +574,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" );