Restrict texts in jquery

by narensrinivasans

HTML

<div id="DivId"> 
    some times we have to decide how much texts we have some times we have to decide how much texts we have some times we have to decide how much texts we have some times we have to decide how much texts we have some times we have to decide how much texts we have some times we have to decide how much texts we have
</div>

<script>
    $.fn.textlimit = function(limit)
{
    return this.each(function(index,val)                       
    {
        var $elem = $(this);
        var $limit = limit;
        var $strLngth = $(val).text().length;  // Getting the text
        if($strLngth > $limit)
        {
          $($elem).text($($elem).text().substr( 0, $limit )+ "...");
        }
    })
};
</script>

CSS

#DivId {
    width: 258px;
}

JavaScript

$("#DivId").textlimit(132);