JavaScript functions

Can I use the clearInterval() function to stop a time display for a countdown clock? Is there a function available to reset the clock or do I have to create my own function?


  • Display the current time (the setInterval() method will execute the function once every 1 second, just like a digital watch). Use clearInterval() to stop time:

    var myVar = setInterval(function(){ myTimer() }, 1000);
    function myTimer() {
        var d = new Date();
        var t = d.toLocaleTimeString();
        document.getElementById("demo").innerHTML = t;
    function myStopFunction() {

    Definition and Usage
    The clearInterval() method clears a timer set with the setInterval() method.

    The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

    Note: To be able to use the clearInterval() method, you must use a global variable when creating the interval method:

    myVar = setInterval("javascript function", milliseconds);
    Then you will be able to stop the execution by calling the clearInterval() method.
    Learn JavaScript here -

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion