Fixes IE9 :checked clone error #873

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+14 −6
Split
View
@@ -454,9 +454,9 @@ 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"
View
@@ -15,7 +15,7 @@ jQuery.support = (function() {
// Preliminary tests
div.setAttribute( "className", "t" );
- div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
+ div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox' checked='checked'/>";
all = div.getElementsByTagName("*");
a = div.getElementsByTagName("a")[ 0 ];
@@ -96,8 +96,8 @@ jQuery.support = (function() {
};
// Make sure checked status is properly cloned
- input.checked = true;
- support.noCloneChecked = input.cloneNode( true ).checked;
+ input.checked = false;
+ support.noCloneChecked = !input.cloneNode( true ).checked;
// Make sure that the options inside disabled selects aren't marked as disabled
// (WebKit marks them as disabled)
@@ -126,6 +126,7 @@ jQuery.support = (function() {
// after being appended to the DOM
input = document.createElement("input");
input.value = "t";
+ input.checked = true
input.setAttribute( "type", "radio" );
support.radioValue = input.value === "t";
@@ -1895,3 +1895,10 @@ test("html() - script exceptions bubble (#11743)", function() {
ok( false, "error ignored" );
}, "exception bubbled from remote script" );
});
+
+test("checked state is cloned with clone()", function(){
+ var elem = jQuery.parseHTML('<input type="checkbox" checked="checked"/>')[0];
+ elem.checked = false;
+ var result = !jQuery(elem).clone().attr('id','clone')[0].checked;
+ ok( result, 'Checked state correctly cloned' );
+});