Skip to content

Instantly share code, notes, and snippets.

@redconfetti
Created April 24, 2014 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redconfetti/11272758 to your computer and use it in GitHub Desktop.
Save redconfetti/11272758 to your computer and use it in GitHub Desktop.
Javascript Asynchronous Loop with clearing
// do something
var doSomething = function() {
var myLink = $('a#ajax-link');
if (myLink.length > 0){
myLink.hide();
stopDoSomethingLoop();
}
};
// do something every 300 milliseconds
var doSomethingLoop = window.setInterval(function() {
doSomething();
}, 300);
// halts check once button replaced
var stopDoSomethingLoop = function() {
window.clearInterval(doSomethingLoop);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment