webadmin's picture

jQuery addclass first and last divs from a list of items

Coding

For instance this set of divs (also is possible with li, a, etc..):

qwe
asd
zxc
ghj
bnm

with Jquery you can select first and last item, in this case, to add a class to first/last target elements (put this in the end of your view results template):

$('.item')
.eq(0).addClass('first').end()
.eq(-1).addClass('last').end();

of course you must have respective class to this different elements, for instance:

.first, .last{
background-color:#0099FF;
}