I have a listing of events and I want the last item to have a different style to the others. Which I've achieved this using the :last-of-type selector and it works fine.
The events can be filtered, so I'm using some jQuery to show/hide events. If the last event is hidden the :last-of-type selector no longer works, as the div is just hidden with the addition of a class.
To try and get around this, I've tried to use the :not() selector as well, but I'm not getting the result I expect.
Here's a quick mockup of the general idea:
$('.box').click(function(){
$(this).addClass('hidden');
});
$('#showBoxes').click(function(){
$('.box').removeClass('hidden');
return false;
});
.box {
padding: 10px;
margin-bottom:10px;
background-color: #f00;
}
.hidden {
display: none;
}
.box:not(.hidden):last-of-type {
background-color: #ff0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
My First Event
</div>
<div class="box">
Conference 117
</div>
<div class="box">
Christmas Party
</div>
<div class="box">
Another Event with some more content - Click to hide!
</div>
<p><a id="showBoxes" href="">Show All Boxes</a></p>
So if the last item is hidden, how can the next item take on the css? Is this even possible like this?