I have a function that is supposed to show how many characters are missing to reach the maximum, however, it only counts after the first key is "clicked".
Here's my code
$("#nome_event").keyup(function(){
var count = $(this).length;
var dif = 30 - count;
$("#count_nome2").html(count);
if(count < 30 ){
$("#count_nome").html(dif);
}
});
<div class="form-group">
<label>Nome do Evento</label>
<input class="form-control" id="nome_event">
<p class="help-block"><small>[<span id="count_nome">30</span> | <span id="count_nome2">30</span> Caracteres por usar]</small></p>
</div>