How to execute something after setInterval is executed?

Home / Uncategorized / How to execute something after setInterval is executed?

Question:
var seconds, sessionLength, breakLength;
$(‘button’).on(‘click’, runTimer);

function runTimer()
{
sessionLength = $(‘#sessionLength’).val();
breakLength = $(‘#breakLength’).val();
seconds = 60;
setInterval(timer, 1000);
}

function timer()
{
$(‘#timer’).append(sessionLength + ‘:’ + seconds–);
$(‘#timer’).remove();
}

I want to execute $(‘#timer’).remove(); after the previous line is executed is there any possible way to do it?


Answer:
i dont understand exactly what you are trying to do, but if you want to do "something after something else", you can either use promises, callbacks or timers.

In your case, you could add another timer, after the #timer update.

i.e
function timer()
{
$(‘#timer’).append(sessionLength + ‘:’ + seconds–);
setTimeout(function() {
$(‘#timer’).remove();
}, 100);

}
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *