twitter/bootstrap — Issue #2380: Trigger event when bootstrap-buttons are pressed
Author: philfreo
Created: 2012-03-02 19:29:45+00:00
State: open

Because `bootstrap-button.js` uses event delegation on the `body` tag to detect and handle clicks on its buttons, it makes it hard for other code to "do something" when the button is pressed and also properly detect whether the button is (after the click) in an activated state or not.

For example, someone might try to do a btn.click() function and then check for `hasClass('active')` -- but that won't work since the active class hasn't been toggled on or off until the event bubbles up all the way to `

`.

A simple solution would be to trigger an event upon button click.
At the end of the `Button.prototype.toggle` function, just add `this.$element.trigger('button-change');`