jquery - Count words between all <strong> elements in div ID -
i can't count's words in strong elements. example http://szymoon.nazwa.pl/jquery/index3.html
$(function() { var text = $.trim($('#strongdiv strong').text()); var charslength = text.length; var wordscount = text.html().split(/\s+/).length; alert(wordscount); });
hir 10 words <#>we have here 8 words , 35 chars<#> <#>sd sa<#>
but script tell have 9.
if u have suggestions nice.
$(function() { var text, charslength=0,wordscount=0; $('#strongdiv strong').each(function() { text = $.trim($(this).text()); charslength += text.length; wordscount += text.split(/\s+/).length; }); $("#output").append("words"+wordscount+"<br/>chars: "+charslength); });
Comments
Post a Comment