Search code examples
jqueryclone

jQuery - clone function doesn't handle the dynamic changes in the element to be cloned


I wish to add an element to the form body which is a clone of the select element (id='name') whenever we change another select element's value (id='class')from the dropdown. The problem is that it creates the clone without regards to whether we have changed the (id='name')'s value to something other than the original. Suppose I have changed the name to "Harry" (and the default was "Please select"), the clone is created with "Please select" and not with "Harry".

I wish the cloning to retain the dynamically changed attributes too (all of them).

Here is the fiddle for the same.


Solution

  • .copy doesnt clone selected value. you can copy them by yourself: http://jsfiddle.net/kcuKT/4/