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.
If you have to have 5 results:

```
var length = $('li').length;
var start = $('.active').index() - 2;
start = start + 5 > length ? length - 6 : start;
start = start < 0 ? 0 : start;
var result = $('li').slice(start, start + 5);

```

should do it.