Nick Kahn
Nick Kahn

Reputation: 20078

nth-of-type selection

I have two sets of ul>li and I'm trying to get the second set of ul>li here is what i have done so far:

div.subject ul:nth-of-type(1) //it returns me both instead of one set

<div class="subject">
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
</ul>
</div>

<div class="subject">
<ul>
<li>g</li>
<li>h</li>
<li>i</li>
<li>j</li>
<li>k</li>
</ul>
</div>

How can i get one set of ul>li ?

Upvotes: 1

Views: 68

Answers (1)

BoltClock
BoltClock

Reputation: 723628

Each of your ul is the first of its type as a child of its own div.subject parent, so your selector selects both.

You should be able to do this instead, which will get you the li in just the second ul:

div.subject:nth-of-type(2) > ul > li

(Of course this will break if you have div.subjects mixed with divs that are not .subject and so on...)

Upvotes: 3

Related Questions