开发者

jQuery find() until? [duplicate]

开发者 https://www.devze.com 2023-04-08 15:16 出处:网络
This question already has answers here: 开发者_JS百科 jQuery: find() children until a certain threshold element is encountered
This question already has answers here: 开发者_JS百科 jQuery: find() children until a certain threshold element is encountered (5 answers) Closed last month.

I'm going through a form checking values but I need to stop before a specific element (#before)

$('#before').closest('form').find('.reqd').each(function() {
    //chacks input
});

I need this to stop before or even better after it reaches #before. I read about nextUntil() but it seems only to work for sibling elements. I need to check all .reqd elements in the form before #before

I bet I'm missing some really simple way to do it.


returning false within an each loop will exit the each loop.

$('#before').closest('form').find('.reqd').each(function() {
  // your code here
  if (this.id === "before") {
    // end each loop after processing #before
    return false;
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消