I have this jQuery code:
var char = 60;
$("#counter").append("You have <strong>" + char + "</strong> char.");
$("#StatusEntry").keyup(function () {
if ($(this).val().length > char) {
$(this).val($(this).val().substr(0, char));
}
var rest = char - $(this).val().length;
$("#counter").html("You have <strong>" + rest + "</strong> char.");
if (rest <= 10) {
$("#counter").css("color", "#ff7777");
}
else {
$("#counter").css("color", "#111111");
}
});
All perfectly! But if instead of val () I have text (), it does not work.
The problem is that at the end of the available char, it starts replacing the text from the very beginning ...... using val perfectly.
Why do I need this in the text? Because I use the wysiwyg plugin and convert my text box to div.
I am trying with .stopPropagation, but this does not work .. trying to return false and nothing ...
I hope for your help!
source
share