0
I made a javascript function to delete table row when the user presses the button, but it is not working.
(function($) {
RemoveTableRow = function(handler) {
var tr = $(handler).closest('tr');
tr.fadeOut(400, function(){
tr.remove();
});
return false;
};
var counter = 1;
jQuery('a.add').click(function(event){
event.preventDefault();
counter++;
var newRow = jQuery('<tr>'+
'<td><input class="form-control" name="cod_Produto" type="text" disabled/></td>'+
'<td>Update software</td>'+
'<td>wd</td>'+
'<td>wd</td>'+
'<td>efe</td>'+
'<td>ewf</td>'+
'<td>wefwe</td>'+
'<td>wef</td>'+
'<td>ewfe</td>'+
'<td><button class="btn btn-danger" type="button" onClick="newRow.remove()"><i class="fa fa-remove"></i></button></td>'+
'</tr>');
jQuery('table.table-bordered').append(newRow);
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="col-lg-12">
<div class="box box-success">
<div class="box-header">
<div class="col-lg-11">Itens</div>
<div class="col-lg-1"><a href="#" title="" class="add"><buttom class="btn btn-success"><i class="fa fa-plus"></i></buttom></a></div>
</div>
<div class="box-body">
<table class="table table-bordered">
<tr>
<th style="width: 80px">Cód</th>
<th>Produto</th>
<th>UN</th>
<th style="width: 40px">Volume</th>
<th>Peso</th>
<th>Unitário</th>
<th>Total</th>
<th>Desconto</th>
<th>Líquido</th>
<th>Excluir</th>
</tr>
<tr>
<td><input class="form-control" name="cod_Produto" type="text" disabled/></td>
<td>Update software</td>
<td>wd</td>
<td>wd</td>
<td>efe</td>
<td>ewf</td>
<td>wefwe</td>
<td>wef</td>
<td>ewfe</td>
<td></td>
</tr>
</table>
</div>
</div>
</div>
what is the error? this snippet code is not missing the
html
? , in addition, in the row where thetd
with thebutton
, has many double quotes that are probably giving error, from a look at these points– Ricardo Pontual
You’re not accusing mistakes here
– Lucas Fonseca
Edit your question include html so we can simulate your problem.
– Caique Romero
Look there, I edited there
– Lucas Fonseca