I have a script that looks similar to the following:
function1() {
for(i < 5) {
function2(i);
}
}
function2(i) {
$jqueryHere;
}
Basically, I have a for loop which calls the second function a certain number of times. However, the second function contains only jQuery and I don't know how to force the for loop to wait for the execution of function2() to be finished before moving on and going to the next iteration and increasing the variable i.
EDIT: Here is the specific jQuery code in second function (I'm using typed.js to write lines out on my site):
function type(n, text, print) {
$('#line' + (n + 1)).typed({
strings: text[i],
typeSpeed: 3,
backDelay: 500,
loop: false,
contentType: 'html',
loopCount: false,
callback: function() {
$('#line' + (n + 1)).siblings('.typed-cursor').remove();
$(print[n]).insertAfter('#line' + (n + 1));
}
});
$(".reset").click(function(){
$('#line' + (n + 1)).typed('reset');
});
}