testndtv testndtv - 2 years ago 95
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

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

This should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download