I have a checkbox-button-group like this:
<div class="btn-group" id="id_group" data-toggle="buttons-checkbox">
<button class="btn myclass" type="button" data-value="0">Value 0</button>
<button class="btn myclass" type="button" data-value="1">Value 1</button>
</div>
And the JS event handler:
$(".myclass").click(function(event) {
console.log($(".myclass.active").length);
console.log($(this).hasClass("active"));
});
I want to get the data-value
for all checked buttons, but on the click event, the active
class is not yet set. That means, when I first click a button, the output is:
>>> 0
>>> false
And the next time I click the same button (i.e., uncheck it), the output is:
>>> 1
>>> true
That means the active
class is being set after the event.
How can I get the real state of the button during the click event?