Reputation: 147
This Table is generating dynamically.
<table class='myTab' id='selectPlaceTable' border='1px'>
<tr>
<td>Something</td>
<td>Something</td>
<td>Something</td>
<td><input type='button' class='buttonRmv' id='buttonRmv' value='+'</td>
</tr>
</table>
jquery Function
$(document).ready(function(){
$(".buttonRmv").on('click',function(){
$(this).parent().parent().remove();
});
});
Upvotes: 0
Views: 617
Reputation: 2200
Try this below code:
$(document).ready(function(){
$('body').on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});
Upvotes: 0
Reputation: 67
Try this:
$(document).ready(function(){
$('body').on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});
Upvotes: 0
Reputation: 4637
Use this
$(document).ready(function(){
$(document.body).on('click',".buttonRmv",function(){
$(this).parent().parent().remove();
});
});
Upvotes: 2
Reputation: 18873
Since you are generating HTML dynamically use event delegation and .closest()
as shown :-
$(document).ready(function(){
$(document.body).on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});
Upvotes: 0