Use my jQuery plugin: jQuery-Shorten. . It handles all cases, uses a text stream: an ellipsis, if available, and very fast.
Download: github.com/MarcDiethelm/jQuery-Shorten
Demo and Doc: http://web5.me/jquery/plugins/shorten/shorten.doc.html
You can customize how the text ends (ellipsis). The default is a three-point char ("...", & hellip ;, Unicode: 2026), but you can use whatever you want, including markup.
The width of the text of the "selected" element (for example, span or div) is measured using Canvas or by placing it in a temporary cell of the table and is reduced (initially using a reasonable assumption of efficiency) and measured again until it (and the added ellipsis or text ) is placed inside the block. The tooltip on the "selected" element displays the full source text.
Marc diethm
source share