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/>
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.