Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to limit the number of words in paragraph by jquery
2034 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));
});
Demo 
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details