how can I abort the jquery each
function?
$.each(big_test_object, function(i)
{
// some code
});
each(function() { // Code // To escape from this block based on a condition: if (something) return false; }); From the documentation of the each method: Returning 'false' from within the each function completely stops the loop through all of the elements (this is like using a 'break' with a normal loop).
You can put any number of Exit For statements in a For Each loop. When used within nested For Each loops, Exit For causes execution to exit the innermost loop and transfers control to the next higher level of nesting. Exit For is often used after an evaluation of some condition, for example, in an If ... Then ...
jQuery stop() Method The stop() method stops the currently running animation for the selected elements.
from the jquery each documentation
We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.
$.each(big_test_object, function(i)
{
if(i == 'yourvalue') {
return false;
}
});
you should return false in your callback
cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With