1
I have this javascript function that counts typed characters in a 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>');
}
}
That way, I call her using the event onkeyup
:
<textarea class="form-control" name="" onkeyup="countPublishCharactersAbout(this)" style="resize: none"></textarea>
When exceeding the limit (in this case, 240 characters) the count is negative and red, but I want to implement an effect equal to what happens on Twitter, where characters that are exceeding the limit are signaled in red, as the image below.
I have good news and bad news: The good news is that this is simpler than it seems to do. The bad news is that it is not possible to do in a
textarea
.– Renan Gomes
Probably one uses a
div contenteditable
, right?– Eduardo Silva