Set text limit using jquery

There is some text comprised of 165 characters. I need to show only the first 155 characters, but the last 5 out of the 155 chars should be replaced with “…..” (elipses), and the remaining characters should be removed. fiddle

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
        var txt= $('div').text();
            alert(txt.charAt(150+ i))
<div style="width:100px">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that


Check out the substring function here, and voilà:

var txt= $('#restrict').text();
if(txt.length > 155)
    $('#result').text(txt.substring(0,150) + '.....');

Leave a Reply

Your email address will not be published. Required fields are marked *