Posts:
Threads:
Joined:
Reputation:
2023-12-10, 10:09 AM Here is a very simple javascript that can count words in a div element using it's 'id'.
[justify]Let's assume below is your div element with the sentences.[/justify]
<div id='yourDivId'> This is an example div with some text. Replace this with your own content.</div>
[html]
var divContent = document.getElementById('yourDivId').innerText || document.getElementById('yourDivId').textContent;
var wordCount = divContent.split(/\s+/).filter(function(word) {
return word.length > 0; }).length;
document.write("Number of words: " + wordCount);
[/html]
[justify]Above is the javascript that will count the number of words inside the div element, you can change the ID to a unique one.[/justify]
[justify]Thanks and welcome to the forum. Happy Coding! :smiling:[/justify]