Carlos Carlos - 9 months ago 43
jQuery Question

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

Answer Source

Check out the substring function here, and voilĂ :

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download