4

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...

2
  • can you be more specific, give us an example of what you want before getting a bunch of downvotes Commented Nov 26, 2017 at 12:47
  • @TemaniAfif ok thanks :) Commented Nov 26, 2017 at 12:58

1 Answer 1

7

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.