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: 
Try this:

```
var $a = ​$( ".active" ),
    $all = $a.​​​​​​siblings().andSelf(),
    i = $all.index( $a ),
    i0 = i < 2 ? 0 
    : i + 5 > $all.length ? $all.length - 5 : i - 2;
    $five = $all.slice( i0, i0 + 5 );

```

$five is your collection.
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/)