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
精彩评论