I've tried all sorts of things but I think i'm getting too complicated and even managed to get chrome to hang with my selector. I'm sure theres a simple way to do this
Select classa
but only when theres no classb
and ignore the last instance of it
<div class="container"> <div class="classa classb"></div> <!-- Dont Select --> <div class="classa"></div> <!-- Select --> <div class="classa"></div> <!-- Dont select last instance --> </div>
For selecting everything but a certain element (or elements). We can use the :not() CSS pseudo class.
Simple selectors (select elements based on name, id, class) Combinator selectors (select elements based on a specific relationship between them) Pseudo-class selectors (select elements based on a certain state)
The .class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class.
I believe you can do this with CSS3 using the :not()
selected (example here)
div.classa:not(.classb):not(:last-child) {}
However, as you know, not many browser supports this, so Javascript might be an easier way...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With