jQuery implementation control text content overflow with ellipsis of... Method of representation

  • 2021-01-14 05:38:36
  • OfStack

This article describes the jQuery implementation to control text overflow with ellipsis (...). The method of representation. To share with you for your reference, as follows:

jQuery method of limiting the number of characters


$(function(){
 // Limit the number of characters 
$(".text").each(function(){
var maxwidth=23;
if($(this).text().length>maxwidth){ $(this).text($(this).text().substring(0,maxwidth)); $(this).html($(this).html()+' ... ');
}
});
});
<div class="text" style="width:150px;"> You kill a thousand knives, how to write so many words, I will be cut off in the middle ah, my god! </div>
<div class="text" style="width:150px;"> You kill a thousand knives, how to write so many words, I will be cut off in the middle ah, my god! </div>

Readers who are interested in more jQuery related content can check out the special features of this site: jQuery Drag Effects and Techniques Summary, jQuery Extended Techniques Summary, jQuery Common Classical Effects Summary, jQuery Animation and Effects Usage Summary, jquery Selection Method Summary and jQuery Common Plugins and Usage Summary

I hope this article is helpful to jQuery program design.


Related articles: