Greg Greg - 8 months ago 31
jQuery Question

Boostrap 3 active state button. How get total active button?

At page I have many button active state of type. I bind to the event click and check how many button have active status. But when I click at first button I get zero.

$(".btn-quote").on("click", function (e) {
var totalActiveQuote= $("").length;

if (totalActiveQuote > 0) {
} else {

What I should do to fix this?


This is because the active class is toggled after your onClick event fires. You could fix it by toggling it on your own.

  $(".btn-quote").on("mouseup", function (e) {
    var totalActiveQiote = $(".btn-quote.myActive").length;