aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorColin Snover <github.com@zetafleet.com>2011-01-09 18:38:44 -0600
committerColin Snover <github.com@zetafleet.com>2011-01-09 18:38:44 -0600
commitb14f02899e74c429effadd88527ffde17650149a (patch)
tree260733dab9c2f575d2c498f7dd1b6da3f26f6d24 /src
parent012f0c3b4bd3d04c2f3e1ea80fc1230901d607d9 (diff)
downloadjquery-b14f02899e74c429effadd88527ffde17650149a.tar.gz
jquery-b14f02899e74c429effadd88527ffde17650149a.zip
Ensure that buildFragment clones elements properly in all browsers. Fixes #3879, #6655. Also improves form element clone tests and fixes bugs in $.fn.clone exposed by these new test cases related to the values of checkboxes and radio buttons in IE.
Diffstat (limited to 'src')
-rw-r--r--src/core.js2
-rw-r--r--src/manipulation.js22
2 files changed, 19 insertions, 5 deletions
diff --git a/src/core.js b/src/core.js
index b9e6d816f..4361577e2 100644
--- a/src/core.js
+++ b/src/core.js
@@ -129,7 +129,7 @@ jQuery.fn = jQuery.prototype = {
} else {
ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
- selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
+ selector = (ret.cacheable ? jQuery(ret.fragment).clone()[0] : ret.fragment).childNodes;
}
return jQuery.merge( this, selector );
diff --git a/src/manipulation.js b/src/manipulation.js
index 493082212..cf533c818 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -420,15 +420,29 @@ function cloneFixAttributes(src, dest) {
if ( nodeName === "object" ) {
dest.outerHTML = src.outerHTML;
- // IE6-8 fails to persist the checked state of a cloned checkbox
- // or radio button
- } else if ( nodeName === "input" && src.checked ) {
- dest.defaultChecked = dest.checked = src.checked;
+ } else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
+ // 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;
+ }
+
+ // IE6-7 get confused and end up setting the value of a cloned
+ // checkbox/radio button to an empty string instead of "on"
+ if ( dest.value !== src.value ) {
+ dest.value = src.value;
+ }
// IE6-8 fails to return the selected option to the default selected
// state when cloning options
} else if ( nodeName === "option" ) {
dest.selected = src.defaultSelected;
+
+ // IE6-8 fails to set the defaultValue to the correct value when
+ // cloning other types of input fields
+ } else if ( nodeName === "input" || nodeName === "textarea" ) {
+ dest.defaultValue = src.defaultValue;
}
// Event data gets referenced instead of copied if the expando