Reputation: 245
I have two HTML image buttons (both are grey color), and whenever user clicks on any button I have to change grey color image to color image (I have 2 color images) and make other button grey. So user can know the active button.
How can I achieve this in CSS?
Upvotes: 0
Views: 1528
Reputation: 1245
Add .button class (for example) to the buttons then use this jQuery code:
$( ".button" ).click(function() {
$('.button' ).removeClass('active');
$( this ).addClass('active');
});
<input type="button" class="button" id="button1" value="Button 1">
<input type="button" class="button" id="button2" value="Button 2">
Then with CSS you set the colors. You can have as many buttons as you want. See the fiddle below to check how it works.
Upvotes: 4
Reputation: 1820
I suppose you want to use something like:
function buttonOnClick(){
$("#button2").css("background-color","Green");
}
<input type="button" onClick="buttonOnClick()">
<input type="button" id="button2">
Upvotes: 0