The following code toggles a button in a group. I enjoy binding to change the CSS of these buttons, in particular the selected button.
<span class="label label-primary">Age</span> <div class="btn-group" id="ageID"> <button type="button" style="width:120px" class="btnMyAge btn-default" id="3">Under 10</button> <button type="button" style="width:120px" class="btnMyAge btn-default" id="1">Under 50</button> <button type="button" style="width:120px" class="btnMyAge btn-default" id="2">Over 50</button> </div> <script> $(".btn-group > .btnMyAge").click(function () { $(this).addClass("active").siblings().removeClass("active"); }) </script>
My custom CSS file:
.btnMyAge, .btn:active { background-color: #ffe13a; }
source share