Search code examples
javascriptjqueryhtmlresetcountdown

Resetting jQuery timer


I need to reset my timer back to 5 seconds. But it doesn't work. Can you help:

  <script type="text/javascript">
      "use strict";
      $(document).ready(function() {      
          $('span.countdown').countdown({seconds: 5, callback: 'alert("Test");', onExpiry: restart}); 
      });

      function restart() { 
          $('span.countdown').countdown('change', {seconds: 5}); 
      } 
  </script>

Solution

  • http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

    you use setTimeout() for a single countdown

    setInterval() to do something every X number of seconds

    and clearTimeout() to reset the counter

    Bojan is right in saying that this is not normal JQuery syntax, is it a plugin or something? Whatever it is it's probably little less than syntactic sugar.

    and yeah the syntax is setTimeout(function(), 5000);