Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixes IE9 :checked clone error #873

Closed
wants to merge 2 commits into from

2 participants

Daniel Chatfield Dave Methvin
Daniel Chatfield

This time with a test to support the need for it.

Dave Methvin dmethvin closed this in 569d064
Dave Methvin
Owner

Thanks @danielchatfield ! :star2: BTW, branch off your master with git checkout -b branchname then make the pull request from the branch. Otherwise, your master will be out of sync with jquery master. It took me several months of messing with git/github before I got it all right.

Dave Methvin dmethvin referenced this pull request from a commit
Dave Methvin Revert "Fix #12127. IE9/10 checks fall off the box on clone. Close gh…
…-873."

This reverts commit 569d064.

Causing test fails in Safari, IE6, and IE7.
de213be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6  src/manipulation.js
@@ -454,9 +454,9 @@ function cloneFixAttributes( src, dest ) {
454 454
 		// IE6-8 fails to persist the checked state of a cloned checkbox
455 455
 		// or radio button. Worse, IE6-7 fail to give the cloned element
456 456
 		// a checked appearance if the defaultChecked value isn't also set
457  
-		if ( src.checked ) {
458  
-			dest.defaultChecked = dest.checked = src.checked;
459  
-		}
  457
+
  458
+		dest.defaultChecked = dest.checked = src.checked;
  459
+
460 460
 
461 461
 		// IE6-7 get confused and end up setting the value of a cloned
462 462
 		// checkbox/radio button to an empty string instead of "on"
7  src/support.js
@@ -15,7 +15,7 @@ jQuery.support = (function() {
15 15
 
16 16
 	// Preliminary tests
17 17
 	div.setAttribute( "className", "t" );
18  
-	div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
  18
+	div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox' checked='checked'/>";
19 19
 
20 20
 	all = div.getElementsByTagName("*");
21 21
 	a = div.getElementsByTagName("a")[ 0 ];
@@ -96,8 +96,8 @@ jQuery.support = (function() {
96 96
 	};
97 97
 
98 98
 	// Make sure checked status is properly cloned
99  
-	input.checked = true;
100  
-	support.noCloneChecked = input.cloneNode( true ).checked;
  99
+	input.checked = false;
  100
+	support.noCloneChecked = !input.cloneNode( true ).checked;
101 101
 
102 102
 	// Make sure that the options inside disabled selects aren't marked as disabled
103 103
 	// (WebKit marks them as disabled)
@@ -126,6 +126,7 @@ jQuery.support = (function() {
126 126
 	// after being appended to the DOM
127 127
 	input = document.createElement("input");
128 128
 	input.value = "t";
  129
+	input.checked = true
129 130
 	input.setAttribute( "type", "radio" );
130 131
 	support.radioValue = input.value === "t";
131 132
 
7  test/unit/manipulation.js
@@ -1895,3 +1895,10 @@ test("html() - script exceptions bubble (#11743)", function() {
1895 1895
 		ok( false, "error ignored" );
1896 1896
 	}, "exception bubbled from remote script" );
1897 1897
 });
  1898
+
  1899
+test("checked state is cloned with clone()", function(){
  1900
+	var elem = jQuery.parseHTML('<input type="checkbox" checked="checked"/>')[0];
  1901
+	elem.checked = false;
  1902
+	var result = !jQuery(elem).clone().attr('id','clone')[0].checked;
  1903
+	ok( result, 'Checked state correctly cloned' );
  1904
+});
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.