Luke101 Luke101 - 5 months ago 24
jQuery Question

How to break out of jQuery each Loop

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?

CMS CMS
Answer

To break a $.each loop, you have to return false in the loop callback.

Returning true skips to the next iteration, equivalent to a continue in a normal loop.

$.each(array, function(key, value) { 
    if(value == "foo") 
        return false; 
});
Comments