Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to break out of .each() iteration [duplicate]

Tags:

jquery

Possible Duplicate:
Nested jQuery.each() - continue/break

Here is my code:

var steps = $("div#f");
steps.each(function () {
    var s = $(this);
    var cs = $(this).find(".Cm");
    cs.each(function () {
        var tc = $(this);
        var err = tc.attr("h");
        if (err == false) {
            this.c = err;//this.c is a global variable
            return this.c;
            break;//here is where the error is being thrown
        }
        else {
            this.c =  {"Eval": err, "S": s, "Cm": tc};
            return this.c;
        }
    });
});

I'm using an .each() iteration to collect values. I thought it functioned like a loop so i thought id use a break statement to break out. This is throwing an "illegal" error. Does anyone know how to break out of an each iteration?

like image 777
dopatraman Avatar asked Mar 06 '12 17:03

dopatraman


1 Answers

use return false. Take a look at this resource: http://gavinroy.com/jquery-tip-how-to-break-out-of-each

like image 190
gtr32x Avatar answered Oct 16 '22 21:10

gtr32x