How to limit the number of words in paragraph by jquery
4946 Views
Hints
If you have paragraph something shown below.
This is paragraph to limit the number of words present. First have to count the word then can limit the words.
After limit - Result: This is paragraph to limit the number of words
JS code
$(document).ready(function(){
var countWords = "This is paragraph to limit the number of words present. First have to count the word then can limit the words.";
var n=0;
for(i=0;i<9;i++)
{
n = countWords.indexOf(" ",n);
n++;
}
alert(countWords.substring(0,n));
});