On the Internet I found such a function for cutting text by count of characters per line:
function cutter (str, charsQuantity, dots) { return str.substring(0, charsQuantity) + dots; } I want to apply it to the table, but I stop on how to return its processed value to each cell.
A table, for example, is this:
<table> <tr> <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus, suscipit!</td> <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, voluptate!</td> </tr> <tr> <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, accusantium?</td> <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati, minus!</td> </tr> </table> I tried options like the options below and similar ones, but obviously somewhere I write something wrong:
$('table tr td').each( function cutter () { return $(this).html().substring(0, 60) + '...'; });
replace? What do you want them? The lines are cut off? I think from the name of the function itself it is clear thatreplaceis a replacement - Vasily Barbashev$(this).html()you take the value and cut out 60 characters from it, and you add the ellipsis, BUT, you do not assign the current value to the current element. And just return it. if you add$(this).html($(this).html().substring(0, 60) + '...'), then everything will work. Ps. as an example, without optimization - Vasily Barbashev