Truncate text/string using jQuery

Yesterday I need to truncate string and I was asking myself "How Can I Truncate A String In jQuery?". There are already many jQuery plugins available to truncate the text/string but there is an issue with these plugin. They actually limits the character length of the text, instead of fitting the text with respect to width of container.

But now, there is a jQuery plugin called "trunk8" which works intelligently and fits the text as per the width of container.

trunk8 is an intelligent text truncation plugin to jQuery. When applied to a large block of text, trunk8 will cut off just enough text to prevent it from spilling over. This plugin measures the content area for spill-over and intelligently chooses the text that best fits in the given space.

To use this plugin, all you need to do is to call "trunk8()" method on the selector.

$(document).ready(function() {
  $('.too-long').trunk8();
});

You can also define the number of lines of text-wrap to tolerate before truncating.

$(document).ready(function() {
  $('.too-long').trunk8({
    lines: 2
  });
});

Visit official website for all the options to customize this plugin.

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...