Luke101 Luke101 - 1 year ago 139
jQuery Question

How to break out of jQuery each Loop

How do I break out of a jQuery


I have tried:

return false;

In the loop but this did not work. Any ideas?

Answer Source

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; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download