var interval = setInterval(Timer, 1000); var sec = 0; var min = 0; function Timer() { sec++; if (sec > 59) { min += 1; sec = 0; } document.getElementById("showsecond").innerHTML = sec; document.getElementById("showminutes").innerHTML = min + ' :'; } function StopTime() { clearInterval(Timer); } 
 body { font-size: 48px; margin: 30px; } 
 <span id="showminutes">0</span> <span id="showsecond">0</span> <button onclick="StopTime()">STOP</button> 

    1 answer 1

    The clearInterval function accepts the identifier returned by setInterval.
    In your case, you pass it a reference to the Timer function, while the identifier is stored in the variable variable.

    Work code:

     function StopTime() { clearInterval(interval); }