I have a form which processes data and puts it in to a csv. A user can add multiple rows to the form to add a new item. To make this a unique item the id is incremented by 1 (ex. item[0] goes to item1)
The form works great but I am trying to add a delete / remove button. It works except I don't want it to remove the very last item.
Below is the code I am using. I am having trouble as this if statement breaks the add crew button.
$('#btnDelelte').click(function () {
//remove the last form item
$('.questions:last-child').remove();
// if only element that remains as ID == 0, disable the "remove" button
if ($('.questions:last-child').attr('id' == 0)
$('#btnDelelte').attr('disabled', 'disabled');
});
If you comment out the if statement, and run the jsfiddle all the buttons work but you are able to delete the last form area.