Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery next() Problem

Tags:

jquery

i have this:

<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 a element after a.current. I did this, but it doenst work.

...

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

i also tried

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

... Arent all the a´s inside .selection siblings and therefore be accesable with the next() selector? I wonder, because it works when i remove the div elements between them.

Would be great if someone knows why this is not working ;).

like image 489
Hans Avatar asked Jan 18 '10 20:01

Hans


2 Answers

From jQuery API browser:

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

That's not the immediately following sibling. You could try using nextAll and adding a :first selector:

$(".selection a.current").nextAll("a:first").hide();
like image 134
Matchu Avatar answered Nov 24 '22 08:11

Matchu


Try:

.nextAll("a:first");

And to get the previous:

.prevAll("a:first");

Demo online: http://jsbin.com/ayasa

like image 22
Sampson Avatar answered Nov 24 '22 09:11

Sampson