-4

I'm trying to build a javascript countdown timer.

I need a visible timer that lets appear a button when it has been finished.

Can anyone help me to build it?

Snazzy Sanoj
  • 804
  • 1
  • 11
  • 28
Jamie
  • 91
  • 1
  • 12
  • 4
    Welcome to SO. Please visit the [help] to see how and what to ask. Your question is currently VERY off topic since SO is not an elancing service. Search the web for `javascript countdown timer` and you will find hundreds – mplungjan Jan 02 '16 at 16:58
  • 3
    The answer to your question is yes, someone does know how to make a timer like that. – j08691 Jan 02 '16 at 16:59

1 Answers1

1

You can do this using setInterval.

Here's a basic demo.

var secondsRemaining = 3;

function updateTime() {
  $("#secs").text(secondsRemaining);
}

updateTime();

var i = setInterval(function() {
  secondsRemaining -= 1;
  if (secondsRemaining > 0){
    updateTime();
  } else {
    clearInterval(i);
    $("#secs").html("<button id='myButton'>Click me!</button>")
  }
}, 1000);

$("#secs").on("click", "#myButton", function(){
  alert("Hello!");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div id="secs"></div>

If you want to read more about how this works, this is a pretty decent tutorial: http://www.sitepoint.com/build-javascript-countdown-timer-no-dependencies/

James Hibbard
  • 16,490
  • 14
  • 62
  • 74