I have a code which should enter or delete the last row as we need an HTML table with AJAX
These are my buttons:
<button class="btn btn-success addmore" type="button" id="insert-more"> Agregar Artículo</button>
<button class="btn btn-success removebutton" type="button" id="delete-more"> Eliminar Último artículo</button>
And this is the AJAX code:
$("#insert-more").click(function () {
$("#mytable").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);
}
});
});
$("#delete-more").click(function () {
$("#mytable").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).remove(tds);
} else {
$(this).remove(tds);
}
});
});
The button to add rows works perfectly, the one that does not work is to eliminate them, I thought I understood the .remove
of Ajax but I see no.