I know there are lots of truncate scripts out there, but I can’t use most of them due to integration issues with the cms I am working on.
Basically I must do it this way:
- get a count of the characters inside a div
- if count exceeds a certain amount (lets say 10 characters) the text inside the div should be cut off and have “…” appended to the end.
Being terrible at javascript here is my lame non-working attempt:
if ($('div.text').val().length > 10) {
//
($('div.text').append('...');
}
Can someone please help?
or
div elements don’t have a “value” as returned by val(), but they do have text or html
and then you probably want to truncate the text like