can someone help me create the following effect using JQuery?:
I have several un-ordered lists on a web page:
<ul><li>01</li><li>02</li><li>03</li><li>04</li><li>05</li><li>06</li><li>07</li><li>08</li></ul><ul><li>01</li><li>02</li><li>03</li><li>04</li><li>05</li><li>06</li><li>07</li><li>08</li></ul>
I want to apply CSS classes using JQuery to create the following:
<ul><li>01</li><li class="color">02</li><li class="color">03</li><li>04</li><li>05</li><li class="color">06</li><li class="color">07</li><li>08</li></ul><ul><li>01</li><li class="color">02</li><li class="color">03</li><li>04</li><li>05</li><li cl开发者_JAVA技巧ass="color">06</li><li class="color">07</li><li>08</li></ul>
(Thank you very much - in advance) - Jhollywood
$("ul li").each(function(i) {
if(i % 3 == 0) $(this).addClass("color");
});
Adjust the mod operation as necessary, your example is kinda misleading.
Try this:
$("ul > li").filter(":nth-child(4n-2), :nth-child(4n-1)").each(function() {
$(this).addClass("color");
});
精彩评论