Question: I'm looking the way to find and select the 5 closest "li" (two, three, four, five and six) with class "active" Any idea?

```
<li class="one">Hello</li>
<li class="two">Hello</li>
<li class="three">Hello</li>
<li class="four active">Hello</li>
<li class="five">Hello</li>
<li class="six">Hello</li>
<li class="seven">Hello</li>
<li class="eight">Hello</li>

```

Thanks :)

Answer: 
You can use `index` and `slice` methods:

```
var $li = $('li');
var ind = $li.filter('.active').index(); 
if ( ind-2 < 0 ) ind = 0;

$li.slice(ind-2, ind+3);

```

<http://jsfiddle.net/dc8Xu/>
A single line answer

```
$('li.active').prevAll().andSelf().slice(-3).add('li.active + *').add('li.active + * + *').css('color','red');

```

Explanation:
First get all the elements before the active item with [`prevAll`](http://api.jquery.com/prevAll/) then add the active item itself, and only return the last 3 items with the [`slice`](http://api.jquery.com/slice/) function. Add the items after the `li.active` with the [`add`](http://api.jquery.com/add/) function containing the special [`+`](http://api.jquery.com/next-adjacent-Selector/) selector

[demo](http://jsfiddle.net/nhP33/)