vendredi 2 octobre 2015

Javascript If statement always executes even though criteria has not been met

Stumped.... Have a very simplistic if statement that always executes even though its condition has not been met. The check is performed on a checkbox on change event, which should not matter.

$(document).on('change', "#AddNewCheked", function (event) {
    var currentFriday = 0;    
    var check = $("#AddNewCheked").is(':checked');
    $('.daySelected').each(function (i, obj) {
        $(this).removeClass('daySelected');
    });

    if (check){
        $('.fc-fri').each(function (i, obj) {
            currentFriday++;
            if (currentFriday == 3 || currentFriday == 5) \
            {                                              \
                alert("Iteration: " + currentFriday);       | This is where the issue is
                $(this).addClass('daySelected');           /
            }                                             /
        });
    }
    else {
        $('.fc-fri').each(function (i, obj) {
            currentFriday++;
            if (currentFriday > 1) {
                $(this).addClass('daySelected');
            }
        });
    }
 });

Any suggestions? I have never ran into a weird situation such as this.

Aucun commentaire:

Enregistrer un commentaire