I want to clone one row of a table, but when I clone, the new element’s name and id will be the same as the element from which it was cloned.
What I need is the cloned elements with a different name and id.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would pass
propa map of key/value pairs to update these values after cloning:Cloned elements don’t exist in the DOM until you add them, so you’re not going to have to worry about duplicate
ids until you do that.Example: http://jsfiddle.net/BbpRA/
Update: In the comment you say you have 20
inputs you need to clone. I would create a function that takes the DOM element and the new id and name. You could even make a small plugin out of it:Usage: