I have the following code which calls another function, i.e.:
$('input[name='f01']:checked').each(function() {
setCBCollection(this);
});
How can I put a delay of say 2 seconds on each call to setCBCollection(this)?
Using
setTimeout:setTimeoutschedules a function to be called N milliseconds later (roughly, these things are not precise).Note that we grab
thisto a variable local to the event handler function, and then the function we pass intosetTimeoutis a closure over that variable (because otherwise, the meaning ofthiswill get lost). More details:thisOff-topic: There’s a syntax error in your original, you’re using
'within a'-quoted string without escaping it. I changed it to"in my code above.