Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate text to fit in 3 lines and show three dots in end In Html

I need to display a text as paragraph, but display only three lines and truncate the test while adding ...(three dots) in the paragraph end.

like image 566
Sundeep Saluja Avatar asked Sep 22 '14 11:09

Sundeep Saluja


People also ask

How do you truncate text in HTML?

Create a function truncate(str, maxlength) that checks the length of the str and, if it exceeds maxlength – replaces the end of str with the ellipsis character "…" , to make its length equal to maxlength . The result of the function should be the truncated (if needed) string.


1 Answers

Calculate max length of string which can fit into 3 lines and use the following script

var maxLength = 140;
var result = yourString.substring(0, maxLength) + '...';
like image 166
zavg Avatar answered Oct 04 '22 21:10

zavg