1

I am trying to add ellipsis on multiline using javascript with the below code. It is working for most of the cases except for one case where the text width is the same as the width of the cell. I wasn't able to not add ellipsis in that case. So I need to check the width as well.

while ($(this).height() > 60) {
  $(this).text(function (index, text) {
    return text.replace(/\W*\s(\S)*$/, '...');
  });
}   
Community
  • 1
  • 1
user3496151
  • 181
  • 1
  • 13

1 Answers1

0

Try a container with overflow:hidden to add an ellipsis to an innner paragraph tag that overflows.

var $container = $(container);
    var $p = $container.find("p");
    var divh = $container.height();

    while ($p.outerHeight()>divh) {
        $p.text(function (index, text) {
            return text.replace(/\W*\s(\S)*$/, '...');
         });
    }
jgreenberg
  • 478
  • 1
  • 4
  • 17