Created
April 24, 2014 23:15
-
-
Save redconfetti/11272758 to your computer and use it in GitHub Desktop.
Javascript Asynchronous Loop with clearing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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