Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make a button hidden when body has class name "dark"

I have two buttons one makes the theme dark and the other one makes the theme light I want the dark button hides when body has class name "dark" and the light button be hidden when body has class name "light".

Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You would do this using CSS. Let’s say you have buttons like this in your HTML:

<body class="light">
  <button class="btn-light">Light</button>
  <button class="btn-dark">Dark</button>
</body>

The CSS to make the appropriate buttons hidden depending on body class is this:

body.light button.btn-dark {
  display: none;
}

body.dark button.btn-light {
  display: none;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading