testndtv testndtv - 5 months ago 10x
Javascript Question

JavaScript to trim after n characters

I have a HTML page which shows a Name dynamically. Now this name (FN LN) can be upto 240 charcaters. But at the UI side, I want to trim the FN/LN after about 50 characters and replace with ...

How can I do this using Javascript/jQuery

$("#FN, #LN").each (function () {
  if ($(this).text().length > 50)
    $(this).text($(this).text().substring(0,50) + '...');

This should work.