I have this javascript function that counts characters typed in textarea
and shows the user:
function countPublishCharactersAbout(val) {
var len = val.value.length;
var count = 240 - len;
if (count < 0) {
$('#about-textarea-counter').html('<span class="text-danger">' + count + '</span>');
} else {
$('#about-textarea-counter').html('<span>' + count + '</span>');
}
}
In this way, I call it using the onkeyup
event:
<textarea class="form-control" name="" onkeyup="countPublishCharactersAbout(this)" style="resize: none"></textarea>
When you exceed the limit (in this case, 240 characters), the count is negative and red, but I want to implement an effect similar to what happens on Twitter, where the characters that are exceeding the limit are indicated in red according to the image below.