0

I have a unordered list like the one below:

<ul id="tabs">
      <li><a href="#tab1">latest news</a></li>
      <li class="active"><a href="#tab2">latest posts</a></li>
      <li><a href="#tab3">latest posts</a></li>
      <li><a href="#tab4">latest posts</a></li>
</ul>

I can't find a jQuery selector that gets the next list item from the one whith the .active class, so if .active is the second one the jQuery selector will give me the third list item.

Thank's

2 Answers 2

3

In one step: jQuery('li.active + li');

See adjacent sibling selectors.

Sign up to request clarification or add additional context in comments.

4 Comments

+1 This answer is preferred, since it only requires one query from the selector engine.
Thank's. Yes you are right, but how do I select the previous list item using this method?
You can't. CSS is short on selectors that select an element based on content that follows the element's start tag.
you'll have use prev() I think.
3
$('ul#tabs li.active').next();

1 Comment

Thank's alot I thought this will select only the next list items that have a class .active.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.