Skip to content

Instantly share code, notes, and snippets.

@Demwunz
Created March 15, 2012 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Demwunz/2045190 to your computer and use it in GitHub Desktop.
Save Demwunz/2045190 to your computer and use it in GitHub Desktop.
JavaScript: trim text
trimText : function(obj, body, length){
var splitLocation = body.indexOf(' ', length);
if(splitLocation != -1) {
// truncate tip
var splitLocation = body.indexOf(' ', length),
str1 = body.substring(0, splitLocation),
str2 = body.substring(splitLocation, length - 1);
obj.html(str1 + '<span class="truncate_ellipsis">&hellip;</span>' + '<span class="truncate_more">' + str2 + '</span>');
obj.find('.truncate_more').css("display", "none");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment