Thursday, December 29, 2016

No width parameter for SPAN tags, so limit width with javascript

$('span').each(function(index, value) {
  var limit = 30;
  var myID = $(this).attr('id');
  if(myID=='decoderip') {
   limit=60;
  }
  var mytext = $(this).text();
  if (mytext.length > limit) {
   // console.log('span text: '+mytext);
   $(this).text(mytext.slice(0, limit) + '...');
  }
 });

No comments: