Hello Everyone,
I have followed below links and below code it is working while user is typing it but while pasting the text the text is limiting to 1000 but the cursor is being reset and allowing user to type the additional text and which is overriding the current text and but not exceeding 1000 characters. I need a solution if user type in the text or pasting the text.
He should not be typing anything more than 1000 and should stop right there, but he can edit the text present in 1000 characters. Please suggest me one solution.
Thanks in advance.
const limit = 200;
rem = limit - $('#editor').text().length;
$("#counter").append("You have <strong>" + rem + "</strong> chars left.");
$("#editor").on('input', function () {
var char = $('#editor').text().length;
rem = limit - char;
$("#counter").html("You have <strong>" + rem + "</strong> chars left.");
console.log(char)
console.log(rem);
if (char >= 100) {
$("#counter").css("color", "#ff7777");
}
else
$("#counter").css("color", "#111111");
if(char>200)
{
$('#editor').text($('#editor').text().substring(0, 200));
}
});