Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: shorten string length to fit a set width

I have a table, and in each cell I want to place strings, but they are much wider than the cell width. To prevent line break, I would like to shorten the strings to fit the cell, and append '...' at end to indicate that the string is much longer.

The table has about 40 rows and has to be done to each cell, so its important that its a quick. Should I use JS/jQuery for this?

How would I do it?

Thank you for your time.

Kind regards,
Marius

like image 464
Marius Avatar asked Mar 30 '10 16:03

Marius


1 Answers

You can use CSS -- text-overflow: ellipsis -- for this - with some caveats for certain browsers and workarounds listed here:

http://mattsnider.com/css/css-string-truncation-with-ellipsis/ (archived)

like image 164
James Westgate Avatar answered Nov 04 '22 22:11

James Westgate