Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Word Count with javascript without input tag

I want to make a word count without any input tag. I want to use just p tag and span tag. How can I make it?

<span class="word" id="word">Words Number</span> <p class="any" id="any">Here have some text which I want to count</p>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

First, you need to get value of p

let countVal = document.getElementById('wordCount');

Then, make an array from it by using split(separator)

let countArr = countVal.split(" ")

Finally, display it in your js

document.getElementById('someId').textContent = countArr.length;
about 4 years ago · Juan Pablo Isaza Report

0

You can use these codes:

For JS: document.querySelectorAll('#word')[0].textContent.length

For Jquery:

$("#word").text().length; 
$("#any").text().length; 
about 4 years ago · Juan Pablo Isaza Report

0

you have same value for class and id in html , change it if possible like this

<span class="Word" id="word">Words Number</span> <p class="Any" id="any">Here have some text which I want to count</p>

Then use this jQuery code

$(document).ready(function(){

var myString = $("#any").text();

var countWord = myString.split(' ').length;

});

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!