mercredi 29 juin 2016

if statement for input value showing even when not true

I'm trying to have the script show me the first character that is typed into an input field only if that character is a specific number. I'm probably missing something simple, but the if statement is returning results to me no matter what number I type in.

HTML

<input class="cardnum">

JS

$('.cardnum').keyup(function(){
  var card = $('.cardnum').val(),
      cardnum = card.charAt(0);
  if ($(cardnum == 3)) {
    console.log(cardnum);
  }
});

Here is a jsFiddle I created in case it helps.

Aucun commentaire:

Enregistrer un commentaire