Hello all,
In my web application, I was dynamically adding/deleting rows from my HTML table using jQuery.
I had a requirement that I needed to delete individual td elements(and not entire row).
My jQuery code is as follows:
$(function () {
/* adding new row to existing table */
// HTML template of a row
$("#contactInfo").each(function () {
$("button.addCommentRow", this).live('click', function () {
var curr_row = $(this).closest('tr');
var html = '<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> ' + col_ninth + '</td> <td><button type="button" class="addCommentRow">+</button> <button type="button" class="deleteCommentRow">-</button> </td> </tr>';
var newRow = $(html).insertAfter(curr_row); // add after the last
newRow.find('.addCommentRow, .deleteCommentRow').button();
newRow.find('.deleteCommentRow').button().click(function () {
newRow.find("td:nth-child(9)").remove();
newRow.find("td:nth-child(10)").remove();
});
});
});
});
So, on deleting I wanted to remove the 9th and the 10th td element from my row.
The above code(only the deletion part) does not seem to work.
Any ideas/suggestions to get working will be highly appreciated.
Thanks,
Pritish.