Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if class exist using only css

I need to change a tag on my html if another tag on my dom is missing a class, I need to check it with out using JS or Jquery, can I do that?

Example:

<a class="collapsed">MY TEXT HERE IS RED</a>

after clicking on this tag the class - > collapsed disappear and I need my text to change to green. the only change in my code is the collapsed been disappeared so according to that I need to change my text color I need the hasClass function in css...

like image 500
Damkulul Avatar asked Oct 30 '25 03:10

Damkulul


1 Answers

Why not simply use :not() selector like this :

a:not(.collapsed) {
  color: green;
}

a.other {
  color:red;
}
<a class="collapsed">MY TEXT HERE IS RED</a>
<a>MY TEXT HERE IS green</a>
<a class="other">MY TEXT HERE IS RED</a>
like image 77
Temani Afif Avatar answered Nov 01 '25 16:11

Temani Afif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!