Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

320
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda