There is such a code to add a formset for the site. You need to add a delete button to each new formset. Accordingly, the buttons will have the same id as the formset. Can you please tell me how to make buttons with different id ?
$('#add_issueforinvoice').on('click', function(e){ e.preventDefault(); var form_count = $('#id_invoiceforproject_set-TOTAL_FORMS').val(), id = '#invoice_' + (parseInt(form_count)), prev = parseInt(form_count), count = parseInt(form_count) + 1, form_group = $('#invoice_1'); var new_form_group = form_group.clone().prop( 'id', 'invoice_' + count ).insertAfter($(id)); $('#invoice_' + count).find('div').prop('id', function(index, id) { if (this.id) return this.id.replace('set-0-', 'set-' + (count - 1) + '-'); }); $('#invoice_' + count).find('select').prop('id', function(index, id) { if (this.id) return this.id.replace('set-0-', 'set-' + (count - 1) + '-'); }); $('#invoice_' + count).find('select').prop('name', function(index, id) { if (this.name) return this.name.replace('set-0-', 'set-' + (count - 1) + '-'); }); $('#invoice_' + count).find('label').attr('for', function(index, id) { if (this.for) return this.id.replace('set-0-', 'set-' + (count - 1) + '-'); }); $('#invoice_' + count).find('input').prop('name', function(index, id) { if (this.name) return this.name.replace('set-0-', 'set-' + (count - 1) + '-'); }); $('#invoice_' + count).find('input').prop('id', function(index, id) { if (this.id) return this.id.replace('set-0-', 'set-' + (count - 1) + '-'); }); $('#id_invoiceforproject_set-TOTAL_FORMS').val(parseInt(form_count) + 1); <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>