How do I break out of a jQuery each
loop?
I have tried:
return false;
in the loop but this did not work. Any ideas?
Update 9/5/2020
I put the return false;
in the wrong place. When I put it inside the loop everything worked.
breakjqueryloops
How do I break out of a jQuery each
loop?
I have tried:
return false;
in the loop but this did not work. Any ideas?
I put the return false;
in the wrong place. When I put it inside the loop everything worked.
Best Answer
To
break
a$.each
or$(selector).each
loop, you have to returnfalse
in the loop callback.Returning
true
skips to the next iteration, equivalent to acontinue
in a normal loop.