jeudi 19 juin 2014

jQuery recognizing div as a list item


Vote count:

0




I know you're not supposed to put divs inside an unordered list, but lets say we have the markup noted below. with jQuery I would like to target every 3rd list-item: li:nth-child(3n). Looks like jQuery counts the div inside as a list-item as well, even though we specify li:eq(3n). How can we detect every 3rd list-item regardless of what else is inside the parent element. what's the point of even writing li:eq(3n) when 'li' is ignored?


html:



<ul class="hello">
<div class="someDiv">a</div>
<li>one</li>
<li>two</li>
<li>three</li>
<div class="divider">b</div>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>


jQuery:



$("ul.hello li:nth-child(3n)").css('color','red');


fiddle



asked 3 mins ago

Sammy

1,054





Aucun commentaire:

Enregistrer un commentaire