I have an issue with a click event on a bootstrap button group. I am attempting to retrieve the ids of the buttons that are active. Including the one I'm currently clicking on (if it was unselected). The issue is that the current button I'm clicking on doesn't get added as a selected button when I selected it. As if the class active hasn't been applied yet.
Here is my button group:
<div class="btn-group" id = "rbtns" data-toggle="buttons-checkbox" >
<button class="btn rbtn" id = "0">0</button>
<button class="btn rbtn" id = "1">1</button>
<button class="btn rbtn" id = "2">2</button>
<button class="btn rbtn" id = "3">3</button>
<button class="btn rbtn" id = "4">4</button>
</div>
And my action:
$( document ).ready(function() {
$(".rbtn").click(function () {
var data = [];
$('#rbtns .btn.active').each(function() {
data.push($(this).attr('id'));
});
alert ("Data length: " + data.length);
});
How can I make sure I receive all ids the buttons with class active?
The buttons I am using are bootstrap checkbox style buttons. Once you click on them they are selected. And when you click on them they get unselected.