Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:03:33+00:00 2026-06-13T21:03:33+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:03:34+00:00Added an answer on June 13, 2026 at 9:03 pm

    If you desperately want an event each time the class active is added to a button, you could modify the bootstrap.js. active is set/unset in a small function Button.prototype.toggle triggered by click, line 1362-1370 :

    Button.prototype.toggle = function () {
        var $parent = this.$element.closest('[data-toggle="buttons-radio"]')
    
        $parent && $parent
          .find('.active')
          .removeClass('active')
    
        this.$element.toggleClass('active')
      }
    

    change this to

    Button.prototype.toggle = function () {
        var $parent = this.$element.closest('[data-toggle="buttons-radio"]')
    
        $parent && $parent
          .find('.active')
          .removeClass('active')
    
        this.$element.toggleClass('active')
    
        if (this.$element.hasClass('active')) {
            this.$element.trigger('active')
        }
      }
    

    now you have an event you can bind to .myclass

    $(".myclass").on('active', function() {
      console.log($(".myclass.active").length);
      console.log($(this).hasClass("active"));
    });
    

    OR, if you think the above is too dirty – you can extend / modify the Button.prototype (adding methods, options etc) by following the skeleton described here How to Extend Twitter Bootstrap Plugin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a div, I have some checkbox. I'd like when I push a button
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have a checkbox and a radio button group and I want to know
I have a group of radio buttons with a class of laser2 on each
I have implemented a radio button on one of my apps, exactly like this
I have a group of checkboxes and a toggle button to check/uncheck al checkboxes
I have a checkbox with id terms and a submit button in my form
I have an aspx page that contains a checkbox, and a button. The button
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
I have few pairs of button & check box like on my pages (the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.