Here is the javascript code I am using and I want to highlighted the characters after 255 and should be shown in another div with diff color
$( "#testdiv" ).keyup(function() {
if($("#testdiv").text().length>255)
{
var text = $("#info").text()
$("#testdiv").text("")
$("#testdiv").append(text.slice(0,255)+"<div>"+text.slice(255)+"</div>")
}
});
Here is the HTML code,
<div id="testdiv" contenteditable="true">
</div>
With this code the problem I am facing is
- It is updating the cursor position to the beginning of text when I try to update text after 255 characters.
- When there is less than 255 character inside div and I press enter then every time it appends a div enclosing the
<br>
tag.