How do I select the next “n” elements starting from the current element in jQuery?

后端 未结 3 723
离开以前
离开以前 2021-02-05 00:00

How do I select the next \"n\" elements starting from the current element? What I mean is...

 $(this).attr(...);

I want to do this \"n\" times

相关标签:
3条回答
  • 2021-02-05 00:18

    This should work:

    $(this).nextAll().slice(0,4).attr(…)
    

    Update:

    This will work, too:

    $(this).nextAll("*:lt(4)").attr(…)
    
    0 讨论(0)
  • 2021-02-05 00:18

    $(this).slice(start_index, end_index) will select a portion of your selection. You could keep track of your current index in the loop and then apply the .slice(cur_index, cur_index+n) function on the original set when you hit your condition.

    0 讨论(0)
  • 2021-02-05 00:29

    the nextAll method selects the following siblings of an element, optionally filtered by a selector. You could then follow that with a slice to restrict to a smaller n.

    0 讨论(0)
提交回复
热议问题