Issue
$(".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:
$(".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>
Answered By - j08691
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.