How to write the number of characters from inputon .keyupin javasc...">

Easy way to count characters using .keyup in jQuery

<input type="text" />

How to write the number of characters from inputon .keyupin javascript / jQuery?

+5
source share
2 answers
$('input').keyup(function() {
    console.log(this.value.length);
});

keyupis a quick access method for bind('keyup').
And since jQuery 1.7 all of the above is deprecated, we recommend using the method onto bind events, which means that the code should look like this:

$('input').on('keyup', function() {
    console.log(this.value.length);
});
+14
source

Example. This will warn the number of characters.

$('#textBoxId').bind('keyup', function(e){

     alert($(this).val().length);

});

This obviously assumes that the text field has the identifier textBoxId. Otherwise, change the selector iof do not want to give it an identifier for any reason

+3
source

All Articles