I cannot delete the dynamically generated row in a table. I have searched the internet but couldn't found any suitable solution to my problem. I'm sharing what I have done so far:
$("#AddMore").click(function () {
$("#maintable").each(function () {
var tds = '<tr>';
jQuery.each($('tr:last td', this), function () {
tds += '<td>' + $(this).html() + '</td>';
});
tds += '</tr>';
if ($('tbody', this).length > 0) {
$('tbody', this).append(tds);
} else {
$(this).append(tds);
}
});
});
$("#maintable").on('click', "#deleteRow", function () {
$("#deleteRow").closest('tr').remove();
});
This script is just adding rows but I can't delete the row. I have used jQuery remove function but didn't get any result. Please guide me