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.
Not the prettiest code sample I've ever given... but does the trick :)

```
var activeItem = $('li.active');

activeItem.prev('li').addClass('active').prev('li').addClass('active');
activeItem.next('li').addClass('active').next('li').addClass('active');

```

I'm utilizing a feature of jQuery here called chaining. This means that the functions I've used actually return the object itself that the action was performed on. So the `addClass()` function actually returns the item we added the class to. This allows us to "chain" functions together.

### [See it in action here](http://jsfiddle.net/JbPTD/1/)

Reference -

* [`next()`](http://api.jquery.com/next/)
* [`prev()`](http://api.jquery.com/prev/)