jQuery Simple Truncate String

Truncate and add an ellipsis to a string

JavaScript

var title = "This is your title";

var shortText = jQuery.trim(title).substring(0, 10)
    .split(" ").slice(0, -1).join(" ") + "...";

$('body').append('before: ' + title + '<br>' + 'after: ' + shortText);