diff options
author | Daniel Chatfield <chatfielddaniel@googlemail.com> | 2012-07-25 22:23:24 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2012-07-25 22:23:24 -0400 |
commit | 155855b2a9bd95219871210ae7dcacd2a5f7e117 (patch) | |
tree | e9c76e55f1ccac5fea41ba34d748436f1fbc614a | |
parent | a475f1aa4dd7ac96fcd80728ce2738386778f343 (diff) | |
download | jquery-155855b2a9bd95219871210ae7dcacd2a5f7e117.tar.gz jquery-155855b2a9bd95219871210ae7dcacd2a5f7e117.zip |
Fix #12127, fer real. IE9/10 check state on clone. Close gh-875.
-rw-r--r-- | AUTHORS.txt | 1 | ||||
-rw-r--r-- | src/manipulation.js | 5 | ||||
-rw-r--r-- | test/unit/manipulation.js | 12 |
3 files changed, 15 insertions, 3 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt index 774d11b32..51200abaf 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -129,3 +129,4 @@ David Benjamin <davidben@mit.edu> Uri Gilad <antishok@gmail.com> Chris Faulkner <thefaulkner@gmail.com> Elijah Manor <elijah.manor@gmail.com> +Daniel Chatfield <chatfielddaniel@googlemail.com> diff --git a/src/manipulation.js b/src/manipulation.js index 212eaf6bb..d1dcb3768 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -455,9 +455,8 @@ function cloneFixAttributes( src, dest ) { // IE6-8 fails to persist the checked state of a cloned checkbox // or radio button. Worse, IE6-7 fail to give the cloned element // a checked appearance if the defaultChecked value isn't also set - if ( src.checked ) { - dest.defaultChecked = dest.checked = src.checked; - } + + dest.defaultChecked = dest.checked = src.checked; // IE6-7 get confused and end up setting the value of a cloned // checkbox/radio button to an empty string instead of "on" diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 31426e739..4038f1a74 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1895,3 +1895,15 @@ test("html() - script exceptions bubble (#11743)", function() { ok( false, "error ignored" ); }, "exception bubbled from remote script" ); }); + +test("checked state is cloned with clone()", function(){ + expect(2); + + var elem = jQuery.parseHTML("<input type='checkbox' checked='checked'/>")[0]; + elem.checked = false; + equal( jQuery(elem).clone().attr("id","clone")[0].checked, false, "Checked false state correctly cloned" ); + + elem = jQuery.parseHTML("<input type='checkbox'/>")[0]; + elem.checked = true; + equal( jQuery(elem).clone().attr("id","clone")[0].checked, true, "Checked true state correctly cloned" ); +}); |