Find the 5th element with a specified class in a list and add another class in jQuery
- by Répás
I'd like to addClass "green" to the 5th li.hr in every ul containers in my site.
$("ul li.hr").each(function() {
if ($(this).length = 5) {
$(this).addClass("green");
}
});
PS: if its possible with CSS only, tell me how please.
Note that the ul has mixed elements, like:
<li class="a">foo</li>
<li class="b">foo</li>
<li class="hr">foo</li>
<li class="c">foo</li>
<li class="a">foo</li>
<li class="hr">foo</li>
I need the 5th li.hr.