1
text
2

JQuery next () problem

I have it:

<div class="selection"> <a class="current" href="#">1</a> <div class="class">text</div> <a href="#">2</a> <div class="class">text</div> <a href="#">4</a> <div class="class">text</div> <a href="#">5</a> </div> 

I want to select the very next item after a.current. I did it, but it does not work.

...

 $(".selection a.current").next("a").hide(); 

I also tried

 $(".selection").children("a.current").next("a").hide(); 

... arent all a's inside .selection siblings and therefore be accessible with the following () selector? Interesting because it works when I delete div elements between them.

It would be great if someone knew why this did not work;).

+5
source share
2 answers

From jQuery API Browser :

Get immediately the next sibling of each element in the set of matched elements, optionally a filtered selector.

This is not immediately the next brother. You can try using nextAll and add a :first selector:

 $(".selection a.current").nextAll("a:first").hide(); 
+9
source

Try:

 .nextAll("a:first"); 

And to get the previous one:

 .prevAll("a:first"); 

Online demo: http://jsbin.com/ayasa

+4
source

All Articles