Reputation: 588
I want to remove a specific row with a unique id when the user click on a delete img. It does not work when i select 'tr#'+id and then remove.
Here is my code
js
$("#page_body").on('click', 'a.delete_line', function(e) {
var id=$(this).attr("id");
$('tr#'+id).remove();
});
html
<tr id="unitesbudg_roic_assetcenter.V01.aaf.filename">
<td class="value">ANY</td><td class="value">MAIN </td>
<td class="value">false</td>
<td class="value">unitesbudg_roic_assetcenter.V01.aaf.filename</td>
<td class="value">unitesbudg_roic_assetcenter.txt</td>
<td class="value">undefined</td>
<td><a href="#" class="delete_line" id="unitesbudg_roic_assetcenter.V01.aaf.filename"><img src="img/delete.png"></a></td>
</tr>
Also if you can advice me on best practices for such a feature.
Thx a lot in advance
Upvotes: 0
Views: 99
Reputation: 24776
Your JQuery should look something more like this:
$("#page_body").on('click', 'a.delete_line', function(e) {
$(this).closest('tr').remove();
});
Upvotes: 1