/ Published in: JavaScript
I just ripped it from Prototype for use in my jQuery based code.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function truncate(text, length, truncation) { length = length || 30; truncation = (typeof(truncation) == 'undefined') ? '...' : truncation; return text.length > length ? text.slice(0, length - truncation.length) + truncation : String(text); } truncate("Hello World",10,'...');
URL: https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js