multiselect bootstrap buttons
HTML
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container">
<div class="container">
<button id="choice1" data-toggle="button" class="btn btn-secondary option_group1">choice1</button>
<button id="choice2" data-toggle="button" class="btn btn-secondary option_group1">choice2</button>
<button id="choice3" data-toggle="button" class="btn btn-secondary option_group1">choice3</button>
<button onclick="showSelection();">Update Selection</button>
<div id="selection_display">
</div>
</div>
</div>
CSS
.btn-secondary:not(:disabled):not(.disabled):active,
.btn-secondary:not(:disabled):not(.disabled).active,
.show > .btn-secondary.dropdown-toggle {
color: #fff;
background-color: red;
border-color: red;
}
JavaScript
function showSelection() {
jQuery("#selection_display").empty();
jQuery("#selection_display").append("<hr>choice1 active:" + jQuery("#choice1").hasClass('active'));
jQuery("#selection_display").append("<hr>choice2 active:" + jQuery("#choice2").hasClass('active'));
jQuery("#selection_display").append("<hr>choice3 active:" + jQuery("#choice3").hasClass('active'));
}
jQuery(document).ready(function () {
jQuery(".option_group1").on("click", function (e) {
e.stopPropagation();
jQuery(this).button('toggle');
showSelection();
});
});