Alex Novelli
Alex Novelli

Reputation: 24

If Else inside jQuery each not working

If is not blocking the execution of else statement. Help plase!

function checarZero() {
  $(".ps-form-entry--progressbar").each(function() {
    var valorPerc = $(this).val();
    if (parseFloat(valorPerc) === 0) {
      psLib.NotifyShowHide(
        'alert:Você não distribuiu a renda vitalícia.');
      event.preventDefault();
    } else {
      $("#btn-continuar").fadeIn("fast");
    }
  });
}

Upvotes: 0

Views: 465

Answers (2)

Ugo T.
Ugo T.

Reputation: 1068

Just return false to break the loop.

Upvotes: 0

Adrian
Adrian

Reputation: 8607

That's because event is undefined. Given the snippet you provided is your code, you should see an error in your JS console.

The event variable should be passed into checarZero function, for it to be cancelled. From the snippet, it's hard to say what event you're looking for, if you just want to stop the execution of .each loop you must return false;

Upvotes: 1

Related Questions