Mam aktualnie tabelę, która może zawierać N kolumn i N wierszy. W interfejsie mam przycisk do usunięcia ostatniej kolumny, ale nie mogę wymyślić, jak usunąć ostatnie td
ze wszystkich wierszy, co dotychczas osiągnąłem, aby usunąć pierwszy wiersz td
i ostatni wiersz td
, ale zostaw resztę tam.jQuery usuń ostatnią kolumnę tabeli
Tu jest mój kodu (tylko usuwa ostatni tytuł aktualnie):
function removeTableColumn() {
/*
removeTableColumn() - Deletes the last column (all the last TDs).
*/
$('#tableID thead tr th:last').remove(); // Deletes the last title
$('#tableID tbody tr').each(function() {
$(this).remove('td:last'); // Should delete the last td for each row, but it doesn't work
});
}
Am I czegoś brakuje?
Nie wiedziałem o selektorze ': last-child', nice! –