You would clone() it, and before attaching the cloned element to the DOM, you would skip and add a number to each id .
(function() { var count = 0; window.duplicateForm = function() var source = $('form:first'), clone = source.clone(); clone.find(':input').attr('id', function(i, val) { return val + count; }); clone.appendTo('body'); count++; }; })();
jsFiddle .
It starts at 0 , but you can easily run count with 1 .
You can also use closure if you want, i.e.
var cloneForm = function(form, start) { start = start || 0; return function() { var clone = form.clone(); clone.find(':input').attr('id', function(i, val) { return val + start; }); start++; return clone; }; };
Then you would do ...
var cloneContactForm = cloneForm($('#contact-form'), 5); // Now I want to clone it and put it somewhere. $(cloneContactForm()).appendTo('body');
jsFiddle .
alex
source share