3

Is there a way to go to the next element in jQuery .each()?

$(".row").each( function() {
    if ( ... ) 
        //go to next iteration in .each()
});

Thanks

Matt Altepeter
  • 956
  • 1
  • 8
  • 18

3 Answers3

6

Try this:

$(".row").each( function() {
    if ( ! ... ) {
        ... do everything else ...
    }
});

Or:

$(".row").each( function() {
    if ( ... ) 
        return; //go to next iteration in .each()
});
Lee Meador
  • 12,829
  • 2
  • 36
  • 42
3
var rows = $(".row").each( function(idx) {
    var nextRow = rows.eq(idx + 1);
});
Naftali
  • 144,921
  • 39
  • 244
  • 303
3

You just need make a return to exit from anonymous function and go to next iteration.

$(".row").each( function() {
    if ( ... ) 
        return; //go to next iteration in .each()
});
Jorge Loureiro
  • 458
  • 3
  • 11