Well, I understand that JavaScript does not apply to the entire group, because each button is part of a different group, but the documentation says that this is the right way to use with the button tag. This will not be a problem, except that I need them to be justified.
So my question is: how should I use JavaScript on all three buttons in general? It should work as a simple group of switches.
Click one and the rest are not selected. Any advice would be great!
HTML:
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group">
<button type="button" class="btn btn-default">Low Cost/Effeciency</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default active">Average</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">High Cost/Effeciency</button>
</div>
</div>
JavaScript:
$(function() {
$('body').on('click', '.btn-group button', function (e) {
$(this).addClass('active');
$(this).siblings().removeClass('active');
})
});
source
share