aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2012-12-16 10:39:19 -0500
committerRichard Gibson <richard.gibson@gmail.com>2012-12-16 10:39:19 -0500
commit06f46dad9307c17d4aad6add2d3a9b0b2d3b451a (patch)
treec2120879df7da9bdc720e15f5a75681e564ccc93
parent30e2ffbeb869bb2f65ef139633c68a1c62f0e892 (diff)
downloadjquery-06f46dad9307c17d4aad6add2d3a9b0b2d3b451a.tar.gz
jquery-06f46dad9307c17d4aad6add2d3a9b0b2d3b451a.zip
let .attr(checked|selected, true) update the property
-rw-r--r--src/attributes.js2
-rw-r--r--test/unit/attributes.js11
2 files changed, 10 insertions, 3 deletions
diff --git a/src/attributes.js b/src/attributes.js
index bba4efe39..6da68ef11 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -489,7 +489,7 @@ boolHook = {
// Use defaultChecked and defaultSelected for oldIE
} else {
- elem[ jQuery.camelCase( "default-" + name ) ] = true;
+ elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true;
}
return name;
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index a4be43aa5..84f406d1f 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -247,7 +247,7 @@ test( "attr(Hash)", function() {
});
test( "attr(String, Object)", function() {
- expect( 67 );
+ expect( 71 );
var div = jQuery("div").attr("foo", "bar"),
i = 0,
@@ -281,7 +281,14 @@ test( "attr(String, Object)", function() {
equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
- // As of fixing #11115, we make no promises about the effect of .attr on boolean properties
+ // As of fixing #11115, we only guarantee boolean property update for checked and selected
+ $input = jQuery("<input type='checkbox'/>").attr( "checked", true );
+ equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" );
+ equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" );
+ $input = jQuery("<option/>").attr( "selected", true );
+ equal( $input.prop("selected"), true, "Setting selected updates property (verified by .prop)" );
+ equal( $input[0].selected, true, "Setting selected updates property (verified by native property)" );
+
$input = jQuery("#check2");
$input.prop( "checked", true ).prop( "checked", false ).attr( "checked", true );
equal( $input.attr("checked"), "checked", "Set checked (verified by .attr)" );