I have a word counts create in jquery.
However if user press 'Enter'(line break), it will cause 1 character left.
ex.maxlength=10
, if user type abcde, \n, abc
total become 9 characters only and the div
show 1 character left
$(document).ready(function(){
//Word Count
$('.word_count')
.on('input keyup keydown focus', function () {
var maxlength = $(this).attr('maxlength');
var value = $(this).val();
if(value.length > 0) {
$(this).nextAll('div').first().text((maxlength - $(this).val().length));
} else {
$(this).nextAll('div').first().text(maxlength);
}
});
});
i just find out Chrome count characters wrong in textarea
Chrome counts characters wrong in textarea with maxlength attribute