Reputation: 5
I want to traverse from start to target
<a class="start">
<span></span>
</a>
<div class='target'></div>
and I use this line
$(this).next('.target')
$(this) refers to span. am I traverse correctly?
Upvotes: 0
Views: 42
Reputation: 337560
If this
is the span
, it has no siblings, so next
will not work. To get to the .target
div, you need to go up a level in the DOM, then use next
. Try this;
$(this).parent().next(); // = the `.target` div
Alternatively you can use closest()
with a selector:
$(this).closest('a').next();
Upvotes: 5