Search code examples
javascriptjquerycountdown

Show reset button after counter reaches zero


I would like to hide and then show the "Reset" button as soon as the counter reaches zero.

Index.html:

<html>
<head>
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">   
</script>
<script type="text/javascript" src="countdown.js"></script>
</head>
<body>
    <input type="text" id="timer">
    <script type="text/javascript">
        timer = new Countdown();
        timer.init();
     </script>
        <button id="reset">Reset</button>
       <script type="text/javascript">
        $("#reset").click(function(){
        //timer = new Countdown();  
        timer.reset();
        });
        </script>
</body>

</html>

Please see http://jsfiddle.net/orokusaki/o4ak8wzs/1/ for countdown.js


Solution

  • AWolf's answer is a bit fancier than mine, and they made some good points about your code, but I tried to keep mine simple and tried not to change your original code too much.

    Your init() function will now hide the Reset button, and I had the update_target() function show the Reset button when the timer expired.

    Fiddle: http://jsfiddle.net/rgutierrez1014/o4ak8wzs/4/