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 ;).
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();
Try:
.nextAll("a:first");
And to get the previous:
.prevAll("a:first");
Demo online: http://jsbin.com/ayasa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With