jQuery to count words in each paragraph

Find jQuery code to count number of words in each paragraph or HTML <p> tag element. Below jQuery code does following things.
  • Iterates through each paragraph element.
  • Split the paragraph text using space. Split() returns array so take the length of array which represents number of words.
  • Then appends the count to paragraph itself.
$(document).ready(function() {
    $('p').each(function(i) {
        var iTotalWords = $(this).text().split(' ').length;
        $(this).append(" " + iTotalWords + " words ");
See result below

See Complete Code
Feel free to contact me for any help related to jQuery, I will gladly help you.

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..