mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Set the property corresponding to a boolean attribute when setting to true. Fixes #9103.
- Once boolean properties had been modified natively, setting the attribute no longer set the current value
This commit is contained in:
parent
3ed4b22073
commit
5195335cf4
@ -301,7 +301,7 @@ jQuery.extend({
|
|||||||
return jQuery( elem )[ name ]( value );
|
return jQuery( elem )[ name ]( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret, hooks,
|
var ret, hooks, boolProp,
|
||||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||||
|
|
||||||
// Normalize the name if needed
|
// Normalize the name if needed
|
||||||
@ -326,7 +326,12 @@ jQuery.extend({
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Set boolean attributes to the same name
|
// Set boolean attributes to the same name
|
||||||
|
// Also set the DOM property
|
||||||
if ( value === true && !rspecial.test( name ) ) {
|
if ( value === true && !rspecial.test( name ) ) {
|
||||||
|
boolProp = jQuery.propFix[ name ] || name;
|
||||||
|
if ( !rinvalidChar.test( boolProp ) && typeof elem[ boolProp ] === "boolean" ) {
|
||||||
|
elem[ boolProp ] = true;
|
||||||
|
}
|
||||||
value = name.toLowerCase();
|
value = name.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +343,6 @@ jQuery.extend({
|
|||||||
return hooks.get( elem, name );
|
return hooks.get( elem, name );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var boolProp;
|
|
||||||
|
|
||||||
// Align boolean attributes with corresponding properties
|
// Align boolean attributes with corresponding properties
|
||||||
// Do not check the property if the name contains characters
|
// Do not check the property if the name contains characters
|
||||||
|
@ -163,7 +163,8 @@ test("attr(String, Object)", function() {
|
|||||||
equals( jQuery("#name").attr("name"), "something", "Set name attribute" );
|
equals( jQuery("#name").attr("name"), "something", "Set name attribute" );
|
||||||
jQuery("#name").attr("name", null);
|
jQuery("#name").attr("name", null);
|
||||||
equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
|
equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
|
||||||
jQuery("#check2").attr("checked", true);
|
|
||||||
|
jQuery("#check2").prop("checked", true).prop("checked", false).attr("checked", true);
|
||||||
equals( document.getElementById("check2").checked, true, "Set checked attribute" );
|
equals( document.getElementById("check2").checked, true, "Set checked attribute" );
|
||||||
equals( jQuery("#check2").prop("checked"), true, "Set checked attribute" );
|
equals( jQuery("#check2").prop("checked"), true, "Set checked attribute" );
|
||||||
equals( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" );
|
equals( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" );
|
||||||
|
Loading…
Reference in New Issue
Block a user