views:

68

answers:

2

Hi,

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

+3  A: 
$('ul#tabs li.active').next();
Soufiane Hassou
Thank's alot I thought this will select only the next list items that have a class .active.
andreeib
+3  A: 

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

See adjacent sibling selectors.

David Dorward
+1 This answer is preferred, since it only requires one query from the selector engine.
Mathias Bynens
Thank's. Yes you are right, but how do I select the previous list item using this method?
andreeib
You can't. CSS is short on selectors that select an element based on content that follows the element's start tag.
David Dorward
you'll have use `prev()` I think.
Soufiane Hassou
Yes I used prev().
andreeib