How to limit inner text of div to 175 characters?

前端 未结 5 1601
太阳男子
太阳男子 2020-12-24 00:20

I have a div area that has an arbitrary number of characters. I want to limit the amount of characters that show up in there to 175 characters. I mostly found exaple on how

5条回答
  •  眼角桃花
    2020-12-24 00:30

    You can use the the form of text() that takes a function and write something like:

    $("div.some-area").text(function(index, currentText) {
        return currentText.substr(0, 175);
    });
    

提交回复
热议问题