0

I'm looking for a css selector that selects elements of a class who's immediate successor (if there is one) does not have that class.

So lets say I have a div:

<div>
    <span id="1" class="myClass1">
    <span id="2">
    <span id="3" class="myClass1">
    <span id="4" class="myClass1">
    <span id="5">
</div>

This selector would grab spans 1 and 4.

Is this possible without javascript?

b15
  • 2,101
  • 3
  • 28
  • 46

1 Answers1

1

Try this selector:

span + span:not(.myClass1) {
  border: 1px solid blue;
}

This is the adjacent sibling selector, coupled with the not() selector.

Toby
  • 12,743
  • 8
  • 43
  • 75