I want to dynamically delete a row in a form created in Codeigniter .
The problem is that it works for me, removing a div , but when trying to format it, I include bootstrap, so it eliminates the previous div and not the whole row.
<div id="mixes">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control" id="mix" name="mix[]">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<input type="text" class="form-control" id="cant" name="cant[]">
</div>
</div>
<div class="col-sm-1">
<div class="form-group">
<button type="button" class="btn btn-default" id="add_mix" value="adicionar">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
</div>
</div>
and the script:
<script type="text/javascript">
var max_mix = 5; //max 5 row
var x = 0;
$('#add_mix').click (function(e) {
e.preventDefault(); //prevenir nuevos clicks
if (x < max_mix) {
$('#mixes').append('<div class="row">\
<div class="col-sm-6">\
<div class="form-group">\
<input type="text"
class="form-control" id="mix" name="mix[]">\
</div>\
</div>\
<div class="col-sm-4">\
<div class="form-group">\
<input type="text"
class="form-control" id="cant" name="cant[]">\
</div>\
</div>\
<div class="col-sm-1">\
<div class="form-group">\
<a href="#"
class="del_mix btn btn-default"><i class="fa fa-trash"></i></a>\
</div>\
</div>\
</div>');
x++;
}
});
// Remover el div anterior
$('#mixes').on("click",".del_mix",function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
});
</script>