Search code examples
jqueryclone

Cloning a form using jquery - fields are now inactive


I've got a simple form that has a couple of fields being picked up by the click() function.

I'm also cloning the form, and appending it (the aim being to rename the fields, but haven't got there yet).

The difficulty is that after cloning the form, the click() function isn't acting on the cloned field variables. I've tried using live() to clone it like this:

$('#link').live('click', function() {
var cloneFieldset = $('.parentFieldset').clone();
$(this).after(cloneFieldset);
});

Any ideas how to clone the fieldset while keeping the cloned fields able to interact with jquery?


Solution

  • Cannot have two DOM elements with the same ID, so when you clone it, the click handler only applies to the 1st DOM element with that ID.

    If the live, click was affecting a class, than your code should work.