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

156
Vistas
How to execute same functions using different parameters in a loop whenever a button is clicked

I have the following function:

(The array contains HTML DOM elements created by js)

function run(box,pos) {
      setInterval(() => {
        i = pos[0]

        if (i > box.length - 1) {
          i = 0
          box[box.length - 1].classList.remove('color')
        }

        if (i > 0) {
          box[i - 1].classList.remove('color')
        }


        box[i].classList.add('color')
        i++

        pos.unshift(i)
        pos.pop()
        console.log(pos)

      }, 500)
    }

There are three arrays (box) and three positions(pos) as parameters.

The first runs default at the beginning then on pressing a button I want it to stop and run the same function with second parameters and again on pressing the button with third parameters and after that when button is pressed the function should start with the first parameters as a loop.

There's only one button.

about 4 years ago · Juan Pablo Isaza
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