mercredi 1 juin 2016

jQuery - If Else statement not working but works if separated into individual if statements

The code below only works for the if statement, the subsequent else if statements do not fire. But if I separate all 3 into individual if statements everything works fine. How can I make them all play nice together?

Not Working

  if ( headingLength < 1 ) {
    // show error message
    $('.compose-wrap .message-heading .help-block').fadeIn();
  } else if ( messageLength < 1 ) {
    // show error message
    $('.compose-wrap .message-body .help-block').fadeIn();
  } else if ( formtagLength < 1 ) {
    // show error message
    $('.compose-wrap .choose-recipients .help-block').fadeIn();
  }

Working

  if ( headingLength < 1 ) {
    // show error message
    $('.compose-wrap .message-heading .help-block').fadeIn();
  }

  if ( messageLength < 1 ) {
    // show error message
    $('.compose-wrap .message-body .help-block').fadeIn();
  }

  if ( formtagLength < 1 ) {
    // show error message
    $('.compose-wrap .choose-recipients .help-block').fadeIn();
  }

Aucun commentaire:

Enregistrer un commentaire