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

226
Visualizações
How to make HTML/Javascript Countdown with Message at End

I am very new to coding, so please excuse my ignorance. I'm trying to get a countdown that displays the message "AND THE VOTES ARE IN!" when the timer reaches zero. I then want the link https://www.youtube.com/watch?v=26WpGvLpFzw to be displayed 5 seconds after the countdown is over (the message "AND THE VOTES ARE IN!" will be displayed for 5 seconds, then the link will be shown). I currently have the code for the countdown, but not for the messages to be displayed after the countdown is over. My code so far is:

<p> Voting period: <span id="countdowntimer">10 </span> Seconds</p>

<script type="text/javascript">
    var timeleft = 10;
    var downloadTimer = setInterval(function(){
    timeleft--;
    document.getElementById("countdowntimer").textContent = timeleft;
    if(timeleft <= 0)
        clearInterval(downloadTimer);
    },1000);
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use setTimeout, its somewhat similar to setInterval but delays and runs the code inside after a set amount of milliseconds.

<p id="foo"> Voting period: <span id="countdowntimer">10 </span> Seconds</p>

<script type="text/javascript">
  var timeleft = 10;

  //added this next 4 lines for the link
  var a = document.createElement('a');
  var link = document.createTextNode("https://www.youtube.com/watch?v=26WpGvLpFzw");
  a.appendChild(link);
  a.href = "https://www.youtube.com/watch?v=26WpGvLpFzw";

  var downloadTimer = setInterval(function() {
    timeleft--;
    document.getElementById("countdowntimer").textContent = timeleft;
    if (timeleft <= 0) {
      clearInterval(downloadTimer);

      document.getElementById("foo").innerHTML = "AND THE VOTES ARE IN!";
      //added this part for the delay
      setTimeout(function() {
        document.getElementById("foo").innerHTML = "";
        document.getElementById("foo").appendChild(a);
      }, 5000);


    }
  }, 1000);
</script>

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