0

I have a textarea. If there are less than 20 characters in the textarea, the font size must gets bigger (with a class name). If the length is 20 characters or longer, the textarea gets no special treatment regarding the font size.

This code works, but I'm worried on the browser performance. There are dozens of other processes working around the textarea as the user is typing, and this is definitely a nice-to-have feature. Any other ways I could optimize the constant checking everytime the user types a new letter?

$('#text').keyup(function(e){
    if($(this).val().length < 20) {
        $(this).addClass('bigger');
    } else {
        $(this).removeClass('bigger');
    }
});
Andres SK
  • 10,779
  • 25
  • 90
  • 152

0 Answers0