Hri*_*sto 46 jquery jquery-selectors
How do I select the next "n" elements starting from the current element? What I mean is...
$(this).attr(...);
Run Code Online (Sandbox Code Playgroud)
I want to do this "n" times. For the example of n=4:
$(this).attr(...);
$(this).next().attr(...);
$(this).next().next().attr(...);
$(this).next().next().next().attr(...);
Run Code Online (Sandbox Code Playgroud)
or perhaps do it in a loop:
for (i = 0; i < n; i++) {
$(this).next().attr(...);
}
Run Code Online (Sandbox Code Playgroud)
How can I do this? Is there a way I can do this by selecting the next "n" elements or in a loop?
jig*_*fox 61
这应该工作:
$(this).nextAll().slice(0,4).attr(…)
Run Code Online (Sandbox Code Playgroud)
更新:
这也有效:
$(this).nextAll("*:lt(4)").attr(…)
Run Code Online (Sandbox Code Playgroud)