Disable and enable buttons (Bootstrap) using a jQuery extension

print
A nice easy way to disable and re-enable buttons [etc] in Bootstrap with a little extension to the jQuery library.

Add this into the js file, either a custom.js or the main jQuery class file.  Custom being better so it doesn’t get overwriten in the future.

jQuery.fn.extend({
    disable: function (state) {
        return this.each(function () {
            var $this = $(this);
            $this.toggleClass('disabled', state);
        });
    }
});

Then use like this:

$("#button").disable(true);
$("#button").disable(false);

 

 

 

Share this post:
Related Posts
Send data to a Bootstrap modal
php-banner
Create a random string with PHP

Leave a Comment