I have a content that a user enters in that can be any sort of text.
eg
This is some sample text. I can use special characters like <>&<>&<>&<>&<>&<>&<>&<>&<>&<>&
I then display this content in a grid where the text is truncated to 80 characters (to fit in the available space) and if the user mouse overs the text they can see the full string.
I have a function that I call to do this for me.
function GetDescriptionContent(data, type, row){
return
"<span title='" + data.replace(/'/g, ''') + "'>" +
$('<div/>').text(data).html().substring(0, 80) +
"</span>";
}
However when I'm substringing html I sometimes cut up the special chars like &
<
>
Also when there is a special char in the string it will cut the string off prematurely that may otherwise be OK in length.
How can I smartly truncate my HTML string in javascript?