I will try to explain what I want to do. How to switch between multiple classes if the classes are more than 2? When I click on the colored buttons, then container color class will added/exchanged. When I click on the white button, then it removes container color class.
Here is an JSFiddle example for a better understanding: https://jsfiddle.net/bwd86h4e/1/
I hope somebody can help. Thanks.
HTML:
<div class="buttons">
<div class="btn btn-reset"></div>
<div class="btn btn-red"></div>
<div class="btn btn-green"></div>
<div class="btn btn-yellow"></div>
</div>
<div class="container">
When I click on the colored buttons above, then container color class will exchanged. When I click on the white button, then it removes container color class. How to do it?
</div>
CSS:
/* Buttons */
.btn {
display: inline-block;
width: 30px;
height: 30px;
margin: 3px;
cursor: pointer;
border: 2px solid #333;
}
.btn.btn-red { background-color: red; }
.btn.btn-green { background-color: green; }
.btn.btn-yellow { background-color: yellow; }
/* Container */
.container {
max-width: 480px;
margin-top: 20px;
padding: 40px;
border: 2px solid #333;
}
/* Container color classes */
.container.cont-red { background-color: red; }
.container.cont-green { background-color: green; }
.container.cont-yellow { background-color: yellow; }