How to select the last element in a sequence of neighboring elements?
Consider the following markup:
HTML
<ul>
<li class="foo">...</li>
<li class="foo">...</li>
<li class="foo">...</li>
<li class="bar">...</li>
<li class="bar">...</li>
<li class="bar">...</li>
<li class="bar">...</li>
<li class="foo">...</li>
<li class="bar">...</li>
<li class="bar">...</li>
</ul>
The number of consecutive elements fooor baris dynamic. In addition, suppose that the markup cannot be changed in any way.
The selection of adjacent elements is pretty straight forward:
CSS
.foo + .foo,
.bar + .bar { }
Can I select the last item from a series of consecutive items?
source
share