function stripLastChar(td,offset) { for (var c=td.lastChild; c; c=c.previousSibling) { if (c.nodeType == 1) { if (-1 == stripLastChar(c,offset)) return -1; } if (c.nodeType == 3) { var len = c.nodeValue.length; if (len > offset) { var text = c.nodeValue; c.nodeValue = text.substring(0,len-offset-1)+text.substring(len-offset); return -1; } else { offset -= len; } } } return offset; } $j = jQuery; $j(function(){ $j('.maker_news_banner').each(function(){ var h = 60 /* $(this).height() */; var td = $j(this).find('.maker_desc'); if ($j(td).height() > h) { td.attr('title',td.text().replace(/\"/g,'"')); td.append(document.createTextNode('...')); do { stripLastChar(td[0],3); } while ($j(td).height() > h); } }); });