Jquery/bootstrap disable button

If you are using twitter bootstrap there is this exactly behavior already implemented for you.

You just need to change the class .disabled of the element you want to disable.

Like:

$("#previous").addClass('disabled');

Here is my solution:

Javascript

jQuery.fn.extend( {

    bsButtonSetStatus : function( status ) {
        if ( status ) {
            this.removeClass( 'disabled' );
        } else {
            this.addClass( 'disabled' );
        }
    },

} );

CSS

.btn.disabled,
.btn:disabled {
    -webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
    filter: grayscale(100%);
    opacity: 0.25;
    pointer-events: none;
}

Let me show a simple example. Here, a button becomes disabled once you click it.

<button class="btn btn-danger">Click Me</button>

$('.btn-danger').on('click', function() {

    if ($(this).hasClass('disabled')) {
        return false;
    } else {
        $(this).addClass('disabled');
    }
});