How to limit inner text of div to 175 characters?

前端 未结 5 1603
太阳男子
太阳男子 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:29

    Replace div with the correct identifier for your content:

    $("div").text($(this).text().substr(0, 175)+'...');
    

    Remove the ellipses from the end if desired. I would recommend leaving them to let your users know that the text was shortened. If you are just trying to limit the text to 175 without any notice, then you may choose to remove them in that case as well.

提交回复
热议问题