I am using jquery to clone a form input field when user click on Add button everything goes fine, but I have a problem that if I write something in form input field and click Add button, then jQuery will copy that text into new cloned input element also.
You can try a demo: http://jsbin.com/ikebil/2/edit
Steps:
-
Open the link and click render
-
Type something in input field
-
Click on add button it will create a new input field but also copy the text written in the previous one.
Original code: http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding-form-elements/
So I need to remove that text which comes if anything is written in the previous element.
The best solution would be to actually make a copy of the element before it’s being populated with any data, and then use that “safe” copy and clone it.
It’s faster and safer => see working example