Introduction:
Find jQuery code to count number of words in each paragraph or HTML
<p> tag element. Below jQuery code does following things.
HTML:
Para 1: gjhdfj jghdjghdgj jg jkghdjfkg jgdjghdkj hgghjdgh jghdj gjdhgjdhg jgdhgdjk jgdh jdg
Para 2: hgdjfghdgh jghdfgj hgjdhgj hgjd hgjfdhgj hj ghjdfgh djghj hgfj hjgh jgh jghdj hgdj hdgjhd gjh jdgh jdghjd
Para 3: gdfgjk jghdj hgjd hjg hdjg dhjgd
JS:
$(document).ready(function() { $('p').each(function(i) { var iTotalWords = $(this).text().split(' ').length; $(this).append(" " + iTotalWords + " words "); }); });
0 comments :
Post a Comment