Ellipsis or truncate with dots via JavaScript

Javascript Add comments

Steffen Rusitschka wanted a cross-browser text-overflow:ellipsis, so he created it and told us all about it via Ellipsis or “truncate with dots” via JavaScript.

You can see it in action, or download the code. The main ellipsis function:

PLAIN TEXT
JAVASCRIPT:
  1. function ellipsis(e) {
  2.   var w = e.getWidth()10000;
  3.   var t = e.innerHTML;
  4.   e.innerHTML = "" + t + "";
  5.   e = e.down();
  6.   while (t.length> 0 && e.getWidth()>= w) {
  7.     t = t.substr(0, t.length1);
  8.     e.innerHTML = t + "…";
  9.   }
  10. }
[via Ajaxian]

Leave a Reply

Entries RSS Comments RSS Log in