jquery select siblings 'until'

前端 未结 4 2063
温柔的废话
温柔的废话 2020-12-06 11:25

I have a DOM in the form of

&l
4条回答
  •  鱼传尺愫
    2020-12-06 11:47

    You can iterate through the nextAll div siblings elements until you find the following .parent, check this example:

    $('.parent').click(function() {
      $(this).nextAll('div').each(function() {
        if ($(this).is('.parent')) {
          return false; // next parent reached, stop
        }
        $(this).toggleClass('highlight');
      });
    });
    

    Markup used:

    parent 1
    child
    child
    parent 2
    child
    parent 3
    child
    child
    child

    ...

提交回复
热议问题