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

86
Vistas
Stop setInterval function with a button

User have to see all bets in their dashboard so I created a a function every 2secs that loads all players bet 1 and players bet 2. I want to bind the function to a button so it will STOP running continuously when betting is close and waiting for the outcome and START the function again when the betting is open.

Here's my code:

$(document).ready(function(){
 $("#load_bets1").load("loadbet1.php");
    setInterval(function() {
        $("#load_bets1").load("loadbet1.php");
    }, 2000);
});

$(document).ready(function(){
 $("#load_bets2").load("loadbet2.php");
    setInterval(function() {
        $("#load_bets2").load("loadbet2.php");
    }, 2000);
}); 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

setInterval returns an ID that can be passed to clearInterval to stop it.

Example to stop an interval after some time:

let i = 0;
const intervalID = setInterval(() => console.log(i++), 100);
setTimeout(() => clearInterval(intervalID), 1000);

See also the examples at https://developer.mozilla.org/en-US/docs/Web/API/setInterval#examples.

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