I'm creating a simple char counter for text area with jquery to limit the number of chars that a user can submit. I have setup a keyup
event handler to catch the text change event. On IE, $(this).text().length perfectly. The event is fired and when I check the length of the textarea, I get a correct number. However, same thing doesn't work in FF/Chrome. The text().length always return zero (notice in the picture cnt = 0;) even though there are chars in the text area. The code and fiddler image is attached. Can someone see something that I'm doing wrong that makes it work in IE but not other top browsers? Thanks in advance.
//for replying the post by viewers. Limiting the number chars
$(document).on('keyup', '.txtareareply', function (b) {
var cnt = $(this).text().length;
var id = $(this).data("id");
$("#charMaxCountReply" + id).html(cnt + " of 1000 Character Max.")
if (cnt > 1000) {
alert("You have reached the maximum number of characters allowed.");
$(this).html($(this).text().substring(0, 1000));
return;
}
});