0
I created my table this way with button to add and delete lines:
function addAgregado(){
$("#riscos").append("<div>"+$("#riscoform").html()+"</div>");
}
$("#tbUser").on('click', '.remover_campo', function() {
$(this).parents('tr').remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="hs_firstname field hs-form-field">
<label for="educacao">Composição do Agregado Familiar (Parentesco, Nome e Idade) <span style="color: red;">*</span></label>
<button type="button" class="hs-button primary large" onclick="addAgregado()" >Adicionar Familiar</button>
</div>
<div class="hs_firstname field hs-form-field" id="riscos">
</div>
<div id="riscoform" >
<table class="campo" cellspacing="10" id="tbUser">
<tr class="elimininput">
<td style="display: none;">
<div class="hs_firstname field hs-form-field">
<label for="IdAgreg">Id </label>
<input name="IdAgreg[]" type="text" >
</div>
</td>
<td>
<div class="hs_firstname field hs-form-field">
<label for="Parent">Parentesco </label>
<input name="Parent[]" required="required" type="text" placeholder="" data-rule-required="true" data-msg-required="Campo obrigatório" >
<span class="error1" style="display: none;">
<i class="error-log fa fa-exclamation-triangle"></i>
</span>
</div>
</td>
<td>
<div class="hs_firstname field hs-form-field">
<label for="ParentNome">Nome </label>
<input name="ParentNome[]" required="required" type="text" placeholder="" data-rule-required="true" data-msg-required="Campo obrigatório" >
<span class="error1" style="display: none;">
<i class="error-log fa fa-exclamation-triangle"></i>
</span>
</div>
</td>
<td>
<div class="hs_firstname field hs-form-field">
<label for="ParentIdade">Idade </label>
<input name="ParentIdade[]" required="required" type="text" placeholder="" data-rule-required="true" data-msg-required="Campo obrigatório" >
<span class="error1" style="display: none;">
<i class="error-log fa fa-exclamation-triangle"></i>
</span>
</div>
</td>
<td><button class="remover_campo"><i class="fa fa-trash"></i></button></td>
</tr>
</table>
</div>
If only adding lines works correctly, the problem is when eliminating lines. After deleting a line I can’t add or delete any more lines.
Bruno, you are making clone of a div that has elements with ID, and the ID should be unique, this is wrong. In addition, if you created a new event, you need to assign the click event, events are not copied when you do the
append
– Ricardo Pontual