I am trying to change the colour of buttons if they're clicked using jquery.
my code bellow works and it will add the expand class to the clicked button. but I need to know how I can remove the class and add the old class to it if another button is clicked and visa versa.
this is my code now:
$(".mybtn").click(function(){
$(this).removeClass( "mybtn" ).addClass('expand');
});
and the html is like this:
<button name='mybtn' id='mybtn' class='mybtn' value='1'>1</button>
<button name='mybtn' id='mybtn' class='mybtn' value='2'>2</button>
<button name='mybtn' id='mybtn' class='mybtn' value='3'>3</button>
and the css is a simple css with background color:
.mybtn{
background-color:#fff;
}
.expand{
background-color:#000;
}
any help would be appreciated.