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

321
Views
How to get text from an element with space in javascript

The HTML code is pretty much like this

<div class="place" style="top: 4px;">
    <span class>text</span> 
    <span class>text</span>
    <span class>text</span>
</div>

For example with this code

let text = document.querySelector("div.place").textContent; //grab all text

I get all the text like this: thisisanexampletext
Is there a way to get text with spaces after each word?
like this: this is an example text

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First you have to collect all the span elements. You then iterate through this collection and can read the text from each element with innerHTML / innerText. You push this into an array and at the end you can make the desired string out of it with the array function join().

let t = document.querySelectorAll("div.place span");

const text = [];
for(let i = 0; i < t.length; i++) {   
   text.push(t[i].innerHTML);
}

console.log(text.join(' '));
<div class="place" style="top: 4px;">
    <span class>text</span> 
    <span class>text</span>
    <span class>text</span>
</div>

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!