I have a button that when pressed changes background of div
Button code:
<a id="btn1" href="#">Press Me!</a>
Custom classes to which my div should be changes
#main.class1
{
background-color: red;
}
#main.class2
{
background-color: blue;
}
etc...
And finally the script:
$("#btn1").click(function() {
$('#main').removeClass();
$('#main').addClass('class1');
});
$("#btn2").click(function() {
$('#main').removeClass();
$('#main').addClass('class2');
});
$("#btn3").click(function() {
$('#main').removeClass();
$('#main').addClass('class3');
});
It all works but what I am trying to achieve is having only 1 button instead of several. I want this button to keep changing background color every time I press it. Thanks.