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

250
Visualizações
Js setInterval on each table row with different time count

I have a table and on each row I want to run timer according to different max count number for each row.

<tr>
    <td class='timer' data-maxTime='10'></td>
</tr>
<tr>
    <td class='timer' data-maxTime='20'></td>
</tr>

<script>

    $(".timer").each(function(){
                    
        var count = $(this).attr("data-maxTime");
        runTimer($(this),count); 

    });
    
    
    function runTimer(ele,count){
        
        interval = setInterval(function() { 

            timer = count.split(':');

            minutes = parseInt(timer[0], 10);
            seconds = parseInt(timer[1], 10);
            --seconds;
            minutes = (seconds < 0) ? --minutes : minutes;
            
            if (minutes < 0) {
                clearInterval(interval);
            }
            seconds = (seconds < 0) ? 59 : seconds;
            seconds = (seconds < 10) ? '0' + seconds : seconds;

            if(minutes > -1){
                ele.html(minutes + ':' + seconds);
                rideTime = minutes + ':' + seconds;
            }
        },1000);
        
    }
    
</script>

Timer is running for each case , but there is a delay of 1 second for each row. Can anyone please suggest, how these timers start exactly at same time ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem most probably lies in your runTimer function, because you are assigning the result of setInterval to an undefined variable (interval), which will become a global variable. When you call runTimer for the second time, you are actually overwriting that global variable.

Try defining your interval variable first.

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