I have the following code:
<table>
[...]
<tr class="">
<td class="col-md-2">
10.1
</td>
<td class="col-md-8">
Teste
</td>
<td class="col-md-1">
10
</td>
<td class="col-md-1">
<button type="button" class="btn btn-danger remover" data-toggle="modal" data-target="#confirma">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>
[...]
</table>
JS:
function removeEvento() {
jQuery(".remover").click(function(e) {
e.preventDefault();
var linha = jQuery(this).parent().parent();
jQuery("#confirma").modal("show");
jQuery("#sim").click(function(e) {
linha.remove();
jQuery("#confirma").modal("hide");
});
return false;
});
}
function insereEvento(formName, codInput, valoresArray, tabela, item, pontos) {
tabela.append(linha);
removeEvento();
return true;
}
- It runs every time the delete line button is pressed.
- There is a button of this type for each row in a table.
- These lines are inserted by jQuery / JavaScript, so I can not reload the page.
- Problem: When I click the delete button, it opens a modal window, to delete the line, if I click outside or not, the modal closes. The problem is that when I click to delete another record and erase it, the previous record is also deleted.
Thank you in advance.