I'm attempting to select the first item from a group, however I want to exclude certain items from the selection by class.
e.g. In this example, I attempt to select the first .item
that doesn't have the .hide
class. The not()
works, correctly selecting all but the first item, however following first-of-type
doesn't seem to match anything.
To clarify, in this example I'm aiming for:
- 1st item should remain red
- 2nd item (The first
.item
without the.hide
class) should be blue - 3rd item: Green
- 4th item: Green
- 5th item: Red
- 6th item: Green
.item {
background-color: #060;
margin-bottom: 2px;
text-align: center;
color: #FFF;
}
.hide {
background-color: #600;
}
/* The important bit */
.item:not(.hide):first-of-type {
background-color: #006;
}
<div class="item hide">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item hide">5</div>
<div class="item">6</div>
Am I writing the selector incorrectly? Is there an alternative way to do this?