How to break/exit from a each() function in JQuery?

Tebo

I have some code:

$(xml).find("strengths").each(function() {
   //Code
   //How can i escape from this block based on a condition.
});

How can i escape from the "each" code block based on a condition?

Update:

What if we have something like this:

$(xml).find("strengths").each(function() {
   $(this).each(function() {
       //I want to break out from both each loops at the same time.
   });
});

Is it possible to break out from both "each" functions from the inner "each" function?

# 19.03.2013

If you want to continue instead of break out

return true;
Greg

According to the documentation you can simply return false; to break:

$(xml).find("strengths").each(function() {

    if (iWantToBreak)
        return false;
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to get data from each li using jquery each function?

From Dev

How to use each function, this from jquery to Dart Language?

From Dev

how to extract data from html table using jQuery each function

From Dev

How to display each error from JQuery post() function in Laravel?

From Dev

Find closest element from an Each function in jQuery

From Dev

Can not use .next() from $this in jquery each function

From Dev

jQuery each in each function

From Dev

How to break out from jQuery click event function from inside $.each

From Dev

How to add a closure to jQuery .each function?

From Dev

jQuery - how to perform 'each' function on selected elements?

From Dev

How to set Each button's function in Jquery?

From Dev

How to get a list of values with jquery each function

From Dev

How call variable outside function .each with Jquery?

From Dev

jQuery - how to perform 'each' function on selected elements?

From Dev

How to create generic jquery function for each input

From Dev

How to add a closure to jQuery .each function?

From Dev

How iterate a jQuery function for each slide in a slider?

From Dev

How to get a list of values with jquery each function

From Dev

How to trigger a jquery function from a jquery function

From Dev

Any Ideas how to iterate an element in the each loop in jQuery from within a click function within it?

From Dev

how to call a function from another function in Jquery

From Dev

Trying to combine all value from jquery.each function

From Dev

Attempt to create a each() type jQuery function using Javascript from scratch

From Dev

Accessing outer scope from jQuery.each() function

From Dev

Get value from object within JQuery each function

From Dev

$.each() function jQuery on an object

From Dev

jQuery each function $(this) confusion

From Dev

jQuery .each css is not a function

From Dev

jquery each function loop

Related Related

  1. 1

    how to get data from each li using jquery each function?

  2. 2

    How to use each function, this from jquery to Dart Language?

  3. 3

    how to extract data from html table using jQuery each function

  4. 4

    How to display each error from JQuery post() function in Laravel?

  5. 5

    Find closest element from an Each function in jQuery

  6. 6

    Can not use .next() from $this in jquery each function

  7. 7

    jQuery each in each function

  8. 8

    How to break out from jQuery click event function from inside $.each

  9. 9

    How to add a closure to jQuery .each function?

  10. 10

    jQuery - how to perform 'each' function on selected elements?

  11. 11

    How to set Each button's function in Jquery?

  12. 12

    How to get a list of values with jquery each function

  13. 13

    How call variable outside function .each with Jquery?

  14. 14

    jQuery - how to perform 'each' function on selected elements?

  15. 15

    How to create generic jquery function for each input

  16. 16

    How to add a closure to jQuery .each function?

  17. 17

    How iterate a jQuery function for each slide in a slider?

  18. 18

    How to get a list of values with jquery each function

  19. 19

    How to trigger a jquery function from a jquery function

  20. 20

    Any Ideas how to iterate an element in the each loop in jQuery from within a click function within it?

  21. 21

    how to call a function from another function in Jquery

  22. 22

    Trying to combine all value from jquery.each function

  23. 23

    Attempt to create a each() type jQuery function using Javascript from scratch

  24. 24

    Accessing outer scope from jQuery.each() function

  25. 25

    Get value from object within JQuery each function

  26. 26

    $.each() function jQuery on an object

  27. 27

    jQuery each function $(this) confusion

  28. 28

    jQuery .each css is not a function

  29. 29

    jquery each function loop

HotTag

Archive