I have the following list
<ul class="list"> <li>1</li> <li class="foo">2</li> <li class="foo">3</li> <li class="foo">4</li> <li>5</li> </ul> I want to change the color of first and last li's, which has class foo, using css
.list .foo:first-child, .list .foo:last-child { color: red; } But it select nothing. Check this fiddle.
How can I select first and last li's with class foo. If it's not possible with css then how can I do it with jQuery.
liwith classfoo, not just firstli