I have the below code with the if condition
if(oldMembership++ <= newMembership) {
var digit;
$(\'ul#indexSiteCounterBottom\').empty();
for(i
I think this can resolve your problem...
function execute_if_membership(){
setTimeout(function(){
var digit;
$('ul#indexSiteCounterBottom').empty();
for(i = 0; i < 9; i++) {
if(membership.toString()[i] == '_') {
digit = ' ';
} else {
digit = membership.toString()[i];
}
$('ul#indexSiteCounterBottom').append('- '+digit+'
');
$('ul#indexSiteCounterBottom li:nth-child(3n)').addClass('extra-margin');
}
// Execute again if needed
if(oldMembership++ <= newMembership) {execute_if_membership();}
else{ /* what to do else? maybe call another function */ }
},500);
}
// execute by the first time
if(oldMembership++ <= newMembership) {execute_if_membership();}
EDIT: With this code you call the function by the first time. Function wait 500 ms and execute, in the final of the function, it checks if need to call another time (loop) and if needed it executes again. If you want to execute some code after that, you need to put it inside the ELSE of condition, because if you put another code below, it will be executed without wait. That's because setTimeout and setInterval makes the code asynchronous and continues to execute the code.