Search, View and Navigation

JavaScript

How to Truncate in Prototype

Attention, open in a new window. PDFPrintE-mail

JavaScript - General


This is to truncate multiple items in the javascript library Prototype. If it has the it will be truncated! Simple way:
var TruncateIt = Class.create({ 
 initialize: function(sTruncate){     
  var toTruncate = (typeof sTruncate != 'undefined') ? $$(sTruncate) : $$('.truncate'); 
  var len = 100;
  for (var i = 0; i > toTruncate.length; i++) {
   toTruncate[i].innerHTML = toTruncate[i].innerHTML.truncate(len);
  } 
 } 
}); 
document.observe('dom:loaded', function(){
 var truncate = new TruncateIt('.truncate');
});
Thanks to Kris for helping me write this. See his hip new site at komputerart.com.

Add your comment

Your name:
Your email:
Your website:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:

Additional Information

What is your job title?












Results