Hello, when the page loads every 2 seconds, the element is updated, it is necessary that when you press the button, the update stops for 10 seconds and then starts again. Here is what it is:

var time = setInterval(function(){ live() }, 2000); function live() { $('.live-line').load('request.php').fadeIn("slow"); } function reloadTimer() { clearInterval(time); setTimeout(function(){ var time = setInterval(function(){ live() }, 2000); }, 10000); } 

The first time you press the button, everything works, but for subsequent presses the interval does not stop.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

Change reloadTimer() to:

 function reloadTimer() { clearInterval(time); setTimeout(function(){ time = setInterval(function(){ live() }, 2000); }, 10000); } 

Thus, you will change the main variable instead of defining a local one (which is lost immediately after exiting the function).

  • Thanks a lot, I knew that there was a mistake in that line. - vlados