adding a callback to a for loop
I am trying to get jQuery to remove an element after it as run through a cycle of other functions, but following code block executes the remove()
before it has run any of the for
loop.
function waves(){
for(i=0;i<=10;i++){
wave(x);
};
$(x).remo开发者_Python百科ve();
}
Add an if statement into your loop, that then calls your function.
function waves(){
for(i=0;i<=10;i++){
wave(x);
if (i == 10) {
callback();
}
};
}
function callback() {
$(x).remove();
}
精彩评论