I just want to remove the TR element from current delete image pressed...
I'm doing it:
$( "#btnDelete").click(function() {
$(this).parent().parent().remove();
});
See Fiddle
I can't see why it doesn't work
any tips?
I just want to remove the TR element from current delete image pressed...
I'm doing it:
$( "#btnDelete").click(function() {
$(this).parent().parent().remove();
});
See Fiddle
I can't see why it doesn't work
any tips?
Only one element can have a given ID in an HTML document.
Use a class here and change your code to
$( ".btnDelete").click(function() {
$(this).parent().parent().remove();
});
or better (because more resilient to changes in your HTML) :
$( ".btnDelete").click(function() {
$(this).closest("tr").remove();
});
If your rows or buttons are dynamically added, use the delegation binding :
$(document).on("click", ".btnDelete", function() {
$(this).closest("tr").remove();
});
(instead of document
, you may use any permanent element in which your buttons will be added)
Use a class instead and reference it as .btnDelete
code should change to
$('.btnDelete').click(function(){
$(this).parents('tr').remove();
});
Well, it does work. The thing is you have given the same id for all three buttons. You should consider using a class for that purpose.
You should use classes for your buttons, because IDs have to be unique in your document and for dynamically added elements you have to use event-delegation:
$(document).on('click', '.btnDelete', function(){
$(this).parents('tr').remove();
});