When doing click
an add button , jquery
it generates a append
with 4 inputs
and two buttons, one button deletes the row which works fine, but there is another boton
that must be deleted along with a input
when doing click
it, the problem is that it deletes the div
that I need but in all.
CODE
$('.agregarDireccion').click(function(e) {
e.preventDefault();
$('#direcciones').append(`
<div class="row">
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control" name="direccion[]" placeholder="Dirección Alternativa">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control" name="pais_dir[]" id="pais-dir" placeholder="Pais Actual">
</div>
</div>
<div class="concat-dpto">
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control dpto-dir" name="dpto_dir[]" placeholder="Departamento">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button type="button" class="btn btn-danger remove-dpto-dir" style="border-radius= 50px 50px;">X</button>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control" name="ciu_dir[]" placeholder="Ciudad">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button type="button" class="btn btn-danger remove">Eliminar</button>
</div>
</div>`);
});
//Este es el que borrar el div que necesito, pero se lo borrar a todos los que cree
$('#direcciones').on("click",".remove-dpto-dir",function(e) {
e.preventDefault();
$('.concat-dpto').remove();
});
You need to specify the context using
this
like this: