I need to display some text on two lines, and add some \"...\" if the text is too long.
Example :
This is some long text and we need to show it on only two
var string = "This is some long text and we need to show it on only two lines.".split(" ");
var first_line = string.slice(0,5).join(" ");
var second_line = string.slice(6,10).join(" ");
var display_string = first_line + "
" + second_line;
if(string.length > 10) display_string += "...";
$("#text").html(display_string);
There is definitely a much better way to do this, but this will at least get you started. It shows 5 words per line and adds and ellipsis if there are more than 10 words. Seek a better solution but you can use this until you find one. http://jsfiddle.net/hepW8/