Is there a JS version of a word counter that ignores html tags like <strong> and <i> or html tags like <div id="something"> or <p>
_____________________________
Just Imagine.
_____________________________
Just Imagine.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
document[teal].[/teal]body[teal].[/teal]textContent[teal].[/teal][COLOR=darkgoldenrod]match[/color][teal]([/teal][fuchsia]/\w+/g[/fuchsia][teal]).[/teal]length
document[teal].[/teal]body[teal].[/teal]innerHTML
[teal].[/teal][COLOR=darkgoldenrod]replace[/color][teal]([/teal][fuchsia]/<script[\s\S]*?>[\s\S]*?<\/script\s*>/gi[/fuchsia][teal],[/teal][green][i]' '[/i][/green][teal])[/teal] [gray]// remove scripts[/gray]
[teal].[/teal][COLOR=darkgoldenrod]replace[/color][teal]([/teal][fuchsia]/<style[\s\S]*?>[\s\S]*?<\/style\s*>/gi[/fuchsia][teal],[/teal][green][i]' '[/i][/green][teal])[/teal] [gray]// remove styles[/gray]
[teal].[/teal][COLOR=darkgoldenrod]replace[/color][teal]([/teal][fuchsia]/<\/?\w+[\s\S]*?>/gi[/fuchsia][teal],[/teal][green][i]' '[/i][/green][teal])[/teal] [gray]// remove tags[/gray]
[teal].[/teal][COLOR=darkgoldenrod]replace[/color][teal]([/teal][fuchsia]/&.+?;/g[/fuchsia][teal],[/teal][green][i]''[/i][/green][teal])[/teal] [gray]// remove character entities[/gray]
[teal].[/teal][COLOR=darkgoldenrod]match[/color][teal]([/teal][fuchsia]/\w+/g[/fuchsia][teal])[/teal] [gray]// get the words[/gray]
[teal].[/teal]length [gray]// get their count[/gray]
var renderedText = $('#element').text();
<div id="test">
hello my name is <a href="a.html">bob</a>
</div>
alert($('#test').text());
And so it should for "hello my name is[red]<br>[/red]<a href="a.html">bob</a>" too, but it will concatenate "is" and "bob" into 4 words.Daddy said:gives me "hello my name is bob".