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

308
Views
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 answers
Answer question

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 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!