I currently have a set of buttons in my HTML page:
<button id="button1" onclick="myFunction()" class="buttonClassA"></button>
<button id="button2" onclick="myFunction()" class="buttonClassA"></button>
<button id="button3" onclick="myFunction()" class="buttonClassA"></button>
<button id="button4" onclick="myFunction()" class="buttonClassA"></button>
Here is the CSS file where I defined the style for buttonClassA:
.buttonClassA
{
display: block; width:auto; height:auto; padding:5px; margin-top:10px;
background: #398525; /* old browsers */
background: -moz-linear-gradient(top, #8DD297 0%, #398525 100%); /* firefox */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#8DD297), color-stop(100%,#398525)); /* webkit */
box-shadow: inset 0px 0px 6px #fff;
-webkit-box-shadow: inset 0px 0px 6px #fff;
border: 1px solid #5ea617;
border-radius: 10px;
font:26px times-new-roman;
text-align: center;
text-decoration: none;
color: #147032;
text-shadow: 0px 1px 2px #b4d1ad;
-moz-transition: color 0.25s ease-in-out;
-webkit-transition: color 0.25s ease-in-out;
transition: color 0.25s ease-in-out;
}
My Goal: Update the background color of a button when it's clicked.
How can I achieve this? Would creating another class, say buttonClassB with just a different background color and copying all other attributes from buttonClassA be ideal? If so, how can I dynamically change the class of the button on click event? Your suggestions would be appreciated.