There is a function. An automatic timer is called, which changes the pictures after a certain period of time.
function timer(flag){ var intervalId = setInterval (function(){...} if (flag == 'false') { clearInterval(intervalId); } } Call this function with the parameter false
timer('false'); Works and stops.
When I click on the picture, I want to call this function and stop the timer and then restart from the moment I clicked on the picture.
Writing
$("#cimg2").click(function(event){ timer('false');//останавливает таймер ... код//выполняет нужный мне код timer();//опять запускается таймер } Does not work and does not stop. Removed the timer(); в $("#cimg2").click(function(event) timer(); в $("#cimg2").click(function(event) to check if it stops the timer, it didn’t stop. I can’t understand why in this case it doesn’t stop the timer, and how to make it work.