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

Assign class to tag1 and unassign from tag2 and vice versa with a click

$(".btn1").click(function() { //on each click one class shows and other hides but i cant figure it out
  $(".darktheme").addClass("displaynone");
  $(".whitetheme").removeClass("displaynone");
});
.displaynone {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn1">
<span class="darktheme">Dark Theme</span>
<span class="whitetheme displaynone">White Theme</span>
</button>

>Solution :

Use .toggleClass() instead:

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

$(".btn1").click(function() { //on each click one class shows and other hides but i cant figure it out
  $(".darktheme, .whitetheme").toggleClass("displaynone");
});
.displaynone {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn1">
<span class="darktheme">Dark Theme</span>
<span class="whitetheme displaynone">White Theme</span>
</button>
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