Having difficulty trying to target a particular element in a set that is the last matching selector.
<div class="items">
<article class="today">
this is today
</article>
<article class="today">
this is today
</article>
<article class="today">
this is today
</article>
<article>
Not today
</article>
<article>
Not today
</article>
</div>
My goal is to re-style the last item article.today
.
article {
background: cyan;
}
.today:last-child {
background: black;
color: white;
}
it does not work. http://jsfiddle.net/nv54h/ changing to:
article {
background: cyan;
}
article:last-child {
background: black;
color: white;
}
does work in that last item is now black. http://jsfiddle.net/nv54h/1/ - but without doing two loops or different elements, I can't get it to work as expected (via eg, last-of-type
)
is there any way you can think of targetting the last .today
item only? list is generated via iteration of a collection on the fly that changes in real time so a CSS/markup only solution would be perfect, avoiding logic and back references if item n+1
not today
etc. I guess :last
in Sizzle is an ideal solution but...