Find the 5th element with a specified class in a list and add another class in jQuery
Posted
by
Répás
on Stack Overflow
See other posts from Stack Overflow
or by Répás
Published on 2010-07-13T09:41:07Z
Indexed on
2012/06/01
16:41 UTC
Read the original article
Hit count: 220
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
.
© Stack Overflow or respective owner