I want to improve this function, because when you break the line, it does not count the characters properly:
$(function(){
$("#maxlength").keyup(function(event){
var target = $("#content-countdown");
var max = target.attr('title');
var len = parseInt($(this).val().length);
var remain = max - len;
if (len > max) {
var val = $(this).val();
$(this).val(val.substr(0, max));
remain = 0;
}
target.html(remain);
});
});
HTML
<textarea name="body" maxlength="100" id="maxlength" placeholder="O que está acontecendo?"></textarea>
<input type="submit" name="send" value="Post">
<span id="content-countdown" title="100">100</span>