for example I use following code:
$("img").each(function(i){ x += $("img:eq(" + i ")").width(); if(some conditional) return; });
after return I would like to not adding anything to x, how could I achieve it?
"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."
To break a $. each or $(selector). 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.
The end() method in jQuery is used to end the most recent filtering operation in the current chain and returns the matched set of elements to its previous state. This method is used without any argument. The end() method is useful when jQuery is used for chaining purposes.
The stop() method is an inbuilt method in jQuery which is used to stop the currently running animations for the selected element. Syntax: $(selector). stop(stopAll, goToEnd);
From the JQuery doco...
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.
So essentially this means...
return false;
= break;
return true;
or return;
= continue;
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