I am trying to create the following functionality in my javascript:
$("mySelector").each(function(){
// Do something (e.g. change div class attribute)
// call to MyFunction(), the iteration will stop here as long as it will take for myFunction to complete
});
function myFunction()
{
// Do something for e.g. 5 seconds
}
My question is how can I stop every iteration for the duration of the myFunction()?
setIntervalwill do it once-every-n-miliseconds, andclearIntervalwill stop it when you’re done. This won’t lock up the browser (provided your “do something” also doesn’t). FRAGILE: it assumes that the results of$("mySelector")are valid for the duration of the task. If that isn’t the case then insidedo somethingthen validateitemagain.