Truncate text/string using jQuery
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.