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