I'm not a JS pro, but I figured out a couple ways you could do this.
The HTML:
<p id="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et euismod. Nam commodo consequat libero vel lobortis. Morbi ac nisi at leo vehicula consectetur.</p>
Then with jQuery you truncate it down to a specific character count but leave the last word like this:
// Truncate but leave last word
var myTag = $('#truncate').text();
if (myTag.length > 100) {
var truncated = myTag.trim().substring(0, 100).split(" ").slice(0, -1).join(" ") + "…";
$('#truncate').text(truncated);
}
The result looks like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
elementum consequat tortor et…
Or, you can simply truncate it down to a specific character count like this:
// Truncate to specific character
var myTag = $('#truncate').text();
if (myTag.length > 15) {
var truncated = myTag.trim().substring(0, 100) + "…";
$('#truncate').text(truncated);
}
The result looks like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
elementum consequat tortor et euismod…
Hope that helps a bit.
Here is the jsFiddle.