tags:

views:

211

answers:

2

How do I break out of Jquery's each Loop?

I have tried

 Return false;

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

+3  A: 

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.

CMS
+1  A: 

According to the documentation return false should do the job.

Return false in the callback:

function callback(indexInArray, valueOfElement) {
  var booleanKeepGoing;

  this; // == valueOfElement (casted to Object)

  return booleanKeepGoing; // optional, unless false 
                           // and want to stop looping
}
powtac