With the click of two buttons, I want to switch between two states, let's say state a and state b.
So I got two buttons:
<button id="btnA"> and <button id="btnB">
I also got some divs: bars, fx and table with some initial classes given. Let's say some classes are for state a and some for state b.
So when I click btnA I want the divs to get only the classes meant for state a and so when click btnB make the divs get only the classes meant for state b.
The problem here is that I really don't want switching or toggling, whatever similarities have.
I tried this:
$("#btnA").click(function() {
$(this).removeClass("btn-default")
$(this).addClass("btn-success")
$("#btnB").removeClass("btn-success")
$("#btnB").addClass("btn-default")
$("#table").remove()
$("#bars").switchClass("barsdiferencias barslagrange")
$("#fx").switchClass("fxdiferencias fxlagrange")
})
$("#btnB").click(function() {
$(this).removeClass("btn-default")
$(this).addClass("btn-success")
$("#btnA").removeClass("btn-success")
$("#btnA").addClass("btn-default")
$("#graficos").append('<div id="table" class="table"></div>')
$("#bars").switchClass("barslagrange barsdiferencias")
$("#fx").switchClass("fxlagrange fxdiferencias")
})
I have tried using switchClass and toggleClass but they don't do what I want. I know removing the unwanted classes and adding the proper ones at each function would make it.
But, is there any fancier and shorter code solution?