mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Do not set boolean attributes to empty string on removal. Fixes #10870. +0 bytes compressed
This commit is contained in:
parent
8013163a36
commit
d3320462df
@ -352,7 +352,7 @@ jQuery.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeAttr: function( elem, value ) {
|
removeAttr: function( elem, value ) {
|
||||||
var propName, attrNames, name, l,
|
var propName, attrNames, name, l, isBool,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if ( value && elem.nodeType === 1 ) {
|
if ( value && elem.nodeType === 1 ) {
|
||||||
@ -364,13 +364,17 @@ jQuery.extend({
|
|||||||
|
|
||||||
if ( name ) {
|
if ( name ) {
|
||||||
propName = jQuery.propFix[ name ] || name;
|
propName = jQuery.propFix[ name ] || name;
|
||||||
|
isBool = rboolean.test( name );
|
||||||
|
|
||||||
// See #9699 for explanation of this approach (setting first, then removal)
|
// See #9699 for explanation of this approach (setting first, then removal)
|
||||||
jQuery.attr( elem, name, "" );
|
// Do not do this for boolean attributes (see #10870)
|
||||||
|
if ( !isBool ) {
|
||||||
|
jQuery.attr( elem, name, "" );
|
||||||
|
}
|
||||||
elem.removeAttribute( getSetAttribute ? name : propName );
|
elem.removeAttribute( getSetAttribute ? name : propName );
|
||||||
|
|
||||||
// Set corresponding property to false for boolean attributes
|
// Set corresponding property to false for boolean attributes
|
||||||
if ( rboolean.test( name ) && propName in elem ) {
|
if ( isBool && propName in elem ) {
|
||||||
elem[ propName ] = false;
|
elem[ propName ] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,7 +464,7 @@ test("attr('tabindex', value)", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("removeAttr(String)", function() {
|
test("removeAttr(String)", function() {
|
||||||
expect(9);
|
expect( 10 );
|
||||||
var $first;
|
var $first;
|
||||||
|
|
||||||
equal( jQuery("#mark").removeAttr( "class" ).attr("class"), undefined, "remove class" );
|
equal( jQuery("#mark").removeAttr( "class" ).attr("class"), undefined, "remove class" );
|
||||||
@ -479,6 +479,9 @@ test("removeAttr(String)", function() {
|
|||||||
jQuery("#text1").prop("readOnly", true).removeAttr("readonly");
|
jQuery("#text1").prop("readOnly", true).removeAttr("readonly");
|
||||||
equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
|
equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
|
||||||
|
|
||||||
|
jQuery("#option2c").removeAttr("selected");
|
||||||
|
equal( jQuery("#option2d").attr("selected"), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$first = jQuery("#first").attr("contenteditable", "true").removeAttr("contenteditable");
|
$first = jQuery("#first").attr("contenteditable", "true").removeAttr("contenteditable");
|
||||||
equal( $first.attr('contenteditable'), undefined, "Remove the contenteditable attribute" );
|
equal( $first.attr('contenteditable'), undefined, "Remove the contenteditable attribute" );
|
||||||
|
Loading…
Reference in New Issue
Block a user