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.

demo

$(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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -