Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

303
Visualizações
I am trying to change the color of a div, in a sequence and deleting it after some time

it´s supposed to change the id of a div, wait half a second, and then change the next div's id. i want it to loop only after removing the id from the previous div.

    for(var i=0; i<sequence.length;i++){
        var qS = $("#gamearea .bsq:nth-child("+sequence[i]+")")
        qS.attr({
            id:"acende"
        })
        setTimeout(function(){
            qS.removeAttr("id")
        },500);
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Sounds like an X/Y problem WHY would you want to change the ID? If you want to change colour, add and remove a CLASS –

const sequence = [1, 4, 3, 0, 2]; // 0 based
const $qS = $("#gamearea .bsq");
const len = $qS.length;
let cnt = 0;
setInterval(() => {
  $qS.removeClass("active");
  $qS.eq(sequence[cnt]).addClass("active");
  cnt++;
  if (cnt >= len) cnt = 0;
}, 500)
.active {
  background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<div id="gamearea">
  <div class="bsq">1</div>
  <div class="bsq">2</div>
  <div class="bsq">3</div>
  <div class="bsq">4</div>
  <div class="bsq">5</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda