I have the following form:
<div class="col-md-12 form-group">
<div class="row" id="dep">
<div class="col-md-10">
<input type="text" class="form-control" placeholder="Nome do Dependente" id="dependente[]" name="dependente[]">
</div>
<div class="col-md-2">
<button class="btn btn-primary" type="button" id="adicionar_dependente"><span class="fa fa-plus"></span></button>
</div>
</div>
</div>
And I have the following jQuery:
$("#adicionar_dependente").click(function(){
var campos_novos = "<div class='col-md-10' id='dep_fc' style='margin-top: 5px;'><input type='text' class='form-control' placeholder='Nome do Dependente' id='dependente[]' name='dependente[]'></div><div class='col-md-2' id='dep_fc' style='margin-top: 5px;'><button class='btn btn-primary' type='button' id='deletar_dependente'><span class='fa fa-minus'></span></button></div>";
$("#dep").append(campos_novos);
});
$("#deletar_dependente").click(function(){
$(this).closest('#dep_fc').remove();
});
To add, it usually adds the rows inside the div, but to remove, it does not work. Can anyone tell me where I'm going wrong?