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

151
Views
Cómo cambiar de clase y recuperar la clase usando javascript

Estoy tratando de dar 2 colores diferentes en mis aplicaciones de cuenta regresiva del temporizador.

el temporizador de entrenamiento será verde.

el temporizador de descanso estará en rojo. (y el color será rojo hasta el final)

mi pregunta es cómo hacer que el temporizador vuelva a verde después del temporizador de descanso (rojo) y vuelva a rojo después de verde (temporizador de entrenamiento)

 document.getElementById('start').addEventListener('click', startCountdown); function startCountdown() { let counter = 3, mode = "Workout", rounds = 1; const interval = setInterval(function() { counter--; if (mode == "Workout" && counter >= 0) { id = document.getElementById("count"); id.innerHTML = "ROUND " + rounds + " <br> " + counter; id.classList.add('green') <<<THE FRIST COLOR RUNNING WELL } else { id = document.getElementById("count"); id.innerHTML = "REST " + " <br> " + counter; id.classList.add('red') <<< SECOND COLOR RUNNING WELL } if (counter === 0) { if (mode == "Workout") { mode = "Rest"; } else { mode = "Workout"; rounds++; } id.innerHTML = "DONE"; counter = 3; if (rounds == 21) { clearInterval(interval); } } }, 1000);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

agregue esto cerca de la línea 9 (mode == "Workout" && counter >= 0) ? clsnm="green" : clsnm="red"; y pase esta variable cerca id.classList.add(clsnm)

alternativamente, también puede intentar agregar id.classList.remove('class_name') antes id.classList.add('class_name')

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!