jquery dynamic row number not working properly code example
Example: jquery dynamic row number not working properly
$(function() {
function numberRows($t) {
var c = 0;
$t.find("tr").each(function(ind, el) {
$(el).find("td:eq(0)").html(++c + ".");
});
}
$("#add-service-button").click(function(e) {
e.preventDefault();
var $row = $("<tr>");
$row.append($("<td>"));
$row.append($("<td>").html($("#add-service").val()));
$row.append($("<td>").html("<a class='del-service' href='#' title='Click to remove this entry'>X</a>"));
$row.appendTo($("#service-table tbody"));
numberRows($("#service-table"));
});
$("#form-entry form").submit(function(e) {
e.preventDefault();
$("#add-service-button").trigger("click");
});
$("#service-table").on("click", ".del-service", function(e) {
e.preventDefault();
var $row = $(this).parent().parent();
var retResult = confirm("Are you sure you wish to remove this entry?");
if (retResult) {
$row.remove();
numberRows($("#service-table"));
}
});
});