There is a function like this:

function fun() { setInterval(function() {...}, 1000); } 

This function is called when clicking on an element from the list and with an interval of one second changes the text in another element. When you click on another element, the second same function is launched and both of them already change the value in the element. Actually, how can one execute one setInterval and start another? PS: clearInterval tried to use, but either I handle or not channel.

  • And how did you try to use clearInterval ? - Amandi
  • I have already answered myself. - KoliK

2 answers 2

Yes, it turned out I did not correctly use clearInterval ():

 var val; function fun() { clearInterval(val); val = setInterval(function() {...}, 1000); } 

    When setting the interval, you need to get its ID. To cancel, call clearInterval by passing the interval identifier to it.

    to set the interval:

     var id = setInterval(alert('tick'), 1000); 

    to cancel the interval

     clearInterval(id);