Search code examples
javascriptjqueryreferenceerror

jQuery (JS) error: ReferenceError: Can't find variable: If


I keep getting this

"ReferenceError: Can't find variable: If"

        $(document).ready(function() {

            var row_count = 1;
            var row_tbody = $(".rows").find('tbody');
            var add_row_btn = $(".add_row");
            var rmv_row_btn = $(".rmv_row");

            $(add_row_btn).click(function() {
                $(row_tbody).append('<tr><td><input type="text"></td><td><input type="text"></td><td><input type="text"></td><td><input type="text"></td></tr>');
                $(row_tbody).append('');
                $(row_tbody).append('');
                $(row_tbody).append('');
                row_count++;
            });


                    $(rmv_row_btn).click(function() {
                        If(row_count != 1)
                            $(".rows").find('tbody').find('tr').last().remove();
                });

        });

I have searched around and what I found on this error was that people:

  • Forgot to include jQuery lib
  • Declared the variable in an out of scope place
  • Missed a curly brace or a parenthesis
  • Misc. (from my poorly experienced eyes, the other questions/answers weren't relevant.

But these don't seem to be the problem for me (from what I can see)

So I usually prefer to find the answer instead of asking for it but I have been stuck here for a while and therefore I'm asking here. I hope I won't get scolded for missing some obvious norm (this is my first time asking).

Thanks


Solution

  • you have error in line

    If(row_count != 1) // If with big letter I
    

    change it to

    if(row_count != 1)