I have two buttons. The first one lets appear an alert with a delay of 3 seconds and another one 3 seconds later. The second button must be able to pause the setTimeout
function.
So when the first alert has appeared and I click on 'pause' the second should not show up. I know I'm close to the solution, but it still doesn't work. My code is:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#start").click(function () {
setTimeout(myFunction, 3000);
setTimeout(myFunction, 6000);
});
$("#stop").click(function () {
$("myFunction").stop();
});
});
function myFunction() {
alert('Hello');
}
</script>
</head>
<body>
<p>
<button id="start">Start</button>
<button id="stop">Pause</button>
</p>
</body>
</html>