arozwalak
9/9/2014 - 12:11 PM

Javascript: shorten text

Javascript: shorten text

function shortenText(textLength,elem){

	elem.each(function() {
		var that = $(this),
		title = that.text(),
		chars = title.length;

		if (chars > textLength - 3) {
			var newTitle = title.substring(0, textLength) + "...";
			that.text(newTitle);
		}
	});
}