0
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 of a table.
- These lines are inserted by jQuery/Javascript, so I can’t reload the page.
- Problem: When I click the delete button, it opens a modal window, to delete the line, whether I click outside or not, the modal closes. The problem is that when I click to delete another record and delete it, the previous record is also deleted.
Thanks in advance.
Shows html too, please. You have some unique identifier of the line you want to delete?
– Marllon Nasser
No, to delete I’m doing the following: I pick the handle by clicking, use Parent twice, catching the <tr>. And then I give a line.remove().
– Gabriel Oraboni Carvalho
And where you call
function removeEvento()
?– Marllon Nasser
In the function inserts Wind(). In it I add an event and call the function, otherwise it would not work, I think because the element was added after loading the page, so calling the function works.
– Gabriel Oraboni Carvalho
Please edit your question when you need to add more code to it.
– Math
Gabriel, if any of the answers answered you, mark it as accepting that the question is complete. Unlike a forum, stackoverlow is a Q&A, where a question is considered "solved" when one of the answers is marked as accepted.
– user28595