Skip to content

Commit 06f46da

Browse files
committed
let .attr(checked|selected, true) update the property
1 parent 30e2ffb commit 06f46da

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ boolHook = {
489489

490490
// Use defaultChecked and defaultSelected for oldIE
491491
} else {
492-
elem[ jQuery.camelCase( "default-" + name ) ] = true;
492+
elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true;
493493
}
494494

495495
return name;

test/unit/attributes.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ test( "attr(Hash)", function() {
247247
});
248248

249249
test( "attr(String, Object)", function() {
250-
expect( 67 );
250+
expect( 71 );
251251

252252
var div = jQuery("div").attr("foo", "bar"),
253253
i = 0,
@@ -281,7 +281,14 @@ test( "attr(String, Object)", function() {
281281
equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
282282
equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
283283

284-
// As of fixing #11115, we make no promises about the effect of .attr on boolean properties
284+
// As of fixing #11115, we only guarantee boolean property update for checked and selected
285+
$input = jQuery("<input type='checkbox'/>").attr( "checked", true );
286+
equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" );
287+
equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" );
288+
$input = jQuery("<option/>").attr( "selected", true );
289+
equal( $input.prop("selected"), true, "Setting selected updates property (verified by .prop)" );
290+
equal( $input[0].selected, true, "Setting selected updates property (verified by native property)" );
291+
285292
$input = jQuery("#check2");
286293
$input.prop( "checked", true ).prop( "checked", false ).attr( "checked", true );
287294
equal( $input.attr("checked"), "checked", "Set checked (verified by .attr)" );

0 commit comments

Comments
 (0)