Click here to Skip to main content
15,903,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all...

i ve table. i add row dynamically, i ve button in each row.
once i click the button the particular row will be delete,
i try but the value added dynamically its alway show the table length 1, so i cant delete the row...
Posted
Comments
enhzflep 14-Aug-12 6:45am    
EDIT: Sorry about that, phone went flat. Hence the upper/lower case auto-correction + undeleted 1/2 post.

Its quite simple - the parent of the button is a td, the parent of that td is a trying

function myOnclick(el)
{
var tr, td;
td = el.parentNode;
tr = td.parentNode;
tr.parentNode.removeChild(tr);
}

Then, just attach an onclick function to the button

onclick="myOnclick(this);"

1 solution

It's easy if you use jQuery:

JavaScript
$(yourbutton).closest('tr').remove();


If you add a class "btnRemoveRow" on all your delete-buttons:
JavaScript
$(document).ready(function() {
   $('.btnRemoveRow').click(function(){
      $(this).closest('tr').remove();
   });
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900