Disable button based on attribute in javascript

Eri*_*.18 0 html javascript jquery

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');

    });
Run Code Online (Sandbox Code Playgroud)

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.

jsfiddle

epa*_*llo 5

在控制台中它说:

Uncaught SyntaxError:意外的标识符

查看错误的位置,您可以看到属性方法未正确关闭.

if ($('.questions:last-child').attr('id' == 0)  
Run Code Online (Sandbox Code Playgroud)

它应该是

if ($('.questions:last-child').attr('id') == 0) 
                                        ^
Run Code Online (Sandbox Code Playgroud)