views:

2306

answers:

1

I have a list with links I use with tabs. It looks like this:

<ul>
    <li><a href="#">First tab</a></li>
    <li><a href="#">Second tab</a></li>
    <li class="active"><a href="#">Active tab</a></li>
    <li><a href="#">Fourth tab</a></li>
    <li><a href="#">Fifth tab</a></li>
</ul>

How can I find the list element before and after the active tab? (In this case, the second and fourth tab).

Tried using find, with no success :(

+9  A: 
$("li.active").next();

and

$("li.active").prev();
cletus
Also, if you want to specificly find the next and previous li item, you can just give the methods a selector: $('li.active').next('li');
Tomas Lycken
Thanks, worked exactly like I wanted to! Can't understand why I'm was stumbling around with find() :P
rebellion
To get the two elements in the same set you could do also do something like $("li.active").prev("li").add("li.active + li");.
sighohwell