I found the code below while I was searching for live character count meter, but it does not work for me. I do not know what is the problem.
$(document).ready(function() {
$("#contentbox").keyup(function() {
var box=$(this).val();
var count= 300 - box.length;
if(box.length <= 300) { $("#count").html(count);
} else {
var trimmed = $(this).val().substring(0,300);
$(this).val(trimmed);
}
});
});
<div class="input">
<textarea id="contentbox"></textarea>
<span class="pull-left"><div id="count">300</div></span>
<button class="pull-right">Write</button>
</div>
Any idea?