I am attempting to implement a toggle script on a button by using a CSS class.
Issue: When I click on button2
, it automatically selects button3
, which is incorrect.
Only one button should be active at a time upon clicking.
function togbtn9() {
$("#b1").toggleClass("blueback greyback");
$("#b2").toggleClass("blueback greyback");
$("#b3").toggleClass("blueback greyback");
}
.greyback {
background-color: rgb(240, 240, 240) !important;
color: #000000;
}
.f9 {
font-size: 0.9em !important;
}
.noround {
border-radius: 0px 0px 0px 0px !important;
box-shadow: 0px 0px 4px #CCCCCC;
}
.blueback {
background-color: rgb(10, 102, 60) !important;
color: #FFFFFF !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-12 f9">
<div class="btn-group">
<button type="button" id="b1" onclick="togbtn9()" class="btn blueback f9 noround">Button1</button>
<button type="button" id="b2" onclick="togbtn9()" class="btn f9 greyback noround">Button2</button>
<button type="button" id="b3" onclick="togbtn9()" class="btn f9 greyback noround">Button3</button>
</div>
</div>