Reputation: 312
Suppose I have
<div class="x">
<div class="y"></div>
<div class="y"></div>
<div class="y"></div>
<div class="y"></div>
<div class="y"></div>
<div class="y"></div>
<div class="z"></div>
<div class="y"></div>
<div class="y"></div>
<div class="y"></div>
<div class="z"></div>
</div>
On Click of .y
I need to select .z
which is first one down the order.
What should I write after
$(this). ?
Where this
is the div
I have clicked.
Upvotes: 1
Views: 41
Reputation: 68
.next() will select from the tree downwards, .closest() will search for closest ancestors, try:
$(this).next("div.z");
Upvotes: 0
Reputation: 1235
Use jQuery's nextAll
and first
functions:
var z = $(this).nextAll('.z').first();
Learn more:
https://api.jquery.com/nextAll/
Upvotes: 3
Reputation: 20740
You can use nextAll()
method like following.
$(this).nextAll('.z:first')
Upvotes: 3