-
Notifications
You must be signed in to change notification settings - Fork 264
.clone() documentation is incorrect #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If this is now happening I am thinking it might be because the browsers changed their behavior. Do you have a test case showing the behavior for all inputs including things like |
Here's a test case: http://jsbin.com/OKExOvu/1/edit?html,js,output It only happens with text inputs and checkboxes. Textareas and selects do not retain user input/selection. So my pull request should probably change to reflect that. It happens in Chrome, Firefox and IE as far back as IE8 (IE7 not tested). So it's not a browser change. Since this appears to be so embedded, I'm thinking it's probably better to change the documentation than try to patch jQuery, since there may be applications depending on this behavior. There are also several other questions on stackoverflow referencing this issue. The answers all recommend clearing the value of the new element after cloning. |
Thanks for doing the legwork on this @ithcy. I did seem to remember that If you could update the pull request to mention the exceptions you found, that would be great! |
No problem! Test case updated to include checkboxes, which do appear to retain their [un]checked state when cloned. I will update the pull request shortly. |
As noted in this stackoverflow question:
The docs appear to be wrong. User data typed into inputs is indeed copied to the cloned elements. I verified this with several tests. I could not get .clone() to not copy the value of a text input that whose value was empty in the HTML. The value of the cloned element must be explicitly cleared after cloning if this is the desired result.
The text was updated successfully, but these errors were encountered: