jQuery addclass first and last divs from a list of items

webadmin's picture
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;
}

Baca Juga

JQuery Rocks
15 years 1 month ago
12 years 11 months ago
15 years 3 months ago