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

302
Vistas
How do I flash one word at a time from within a post body to a separate div

I'm trying to flash the individual words from within a post body, into a div one word at a time really really quickly.

var postbody = document.getElementById('postbody');
var posttext = $('#postbody').text();
var postwords = posttext.split(" ");
for (var i=0; i < postwords.length; i+=1) {
    console.log(i)
    setTimeout(function(i)
    {
        $("#flashreadword").fadeOut("slow", function (i)
        {
            currentword = postwords[i];
            console.log(currentword)
            $("#flashreadword").html(currentword);
            $("#flashreadword").show();
        });
    }, 300);
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From the little information you've provided, I've created a sandbox here, this reads the inner text of a postbody on a click of a button then sets innertext of flashreadword every 200ms. I've used async and await you can ofc set timeouts but you may have a condition of running out of sync.

import $ from "jQuery";

$("#submit").click(async () => {
  var posttext = $("#postbody").text();
  var postwords = posttext.split(" ").filter((x) => /[aA-zZ]|[0-9]/.test(x));
  for (var i = 0; i < postwords.length; i++) {
    console.log(postwords);
    await new Promise((r) => setTimeout(r, 200));
    $("#flashreadword").text(postwords[i]);
  }
  $("#flashreadword").text("ALL WORDS COMPLETED");
});

<div id="app">
      <div id="postbody">
        This is my text
      </div>

      <div id="flashreadword"></div>
    </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