1

Is there a good way to select an input that has unique classes.

At the moment this will do...

input[type="checkbox"]:checked + label {....}

But what if I want to grab the label by the class name usethis? Code below -

<div class="checkbox">
   <input id="c1" class="rounded-input" type="checkbox" rel="performance" onchange="change()" />
   <label class="usethis" for="c1">Performance</label>
</div>
3
  • where have used the class name usethis ? Commented May 15, 2020 at 15:58
  • I've edited my snippet its on the label Commented May 15, 2020 at 16:02
  • It's not clear what it is you are trying to achieve. Commented May 15, 2020 at 16:58

1 Answer 1

1

See if this works

input[type="checkbox"]:checked + .usethis {
  color: red;
  font-size: 5rem;  // i have given some random styles here
}

This style will only come when the checkbox is checked, and if you have another checkbox in the page without the label having the class .usethis, this style wont be applied to those checkboxes

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

2 Comments

Awesome, I was concered that removing label in the selector would mess it up. Thanks
Happ to help you

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.