In my work I used to answer this question:
JQuery clone form and increment
How to validate Cloning a form using JQuery Validation?
I tried the following, but it didn't work:
$(document).ready(function () {
$(function () {
var template = $('#attendees .attendee:first').clone(),
attendeesCount = 1;
var addAttendee = function () {
attendeesCount++;
var nativeTemplate = template.clone();
var attendee = nativeTemplate.find(':input').each(function () {
var newId = this.id.substring(0, this.id.length - 1) + attendeesCount;
$(this).prev().attr('for', newId); // update label for (assume prev sib is label)
this.name = this.id = newId; // update id and name (assume the same)
}).end() // back to .attendee
.attr('id', 'att' + attendeesCount) // update attendee id
.prependTo('#attendees') // add to container
.validate(
// rules
);
};
$('.add').click(addAttendee); // attach event
});
});