Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap Buttons

Bootstrap Button

Description

The Bootstrap Button JavaScript plugin lets you enhance button functionality. You can control button states and create button groups for components such as toolbars.

What is required

You must include jquery.js and bootstrap-button.js - these two JavaScript files. Both are located in the docs/assets/js folder.

How to use it

You can use this plugin through markup without writing any JavaScript, or you can enable buttons via JavaScript.

Example

The first example demonstrates how to use the button plugin without JavaScript.

Example

    

        

            

Bootstrap button JavaScript plugin example

            

Controlling states

            

            

Single toggle

            

            

Confirm box

            

                

                

                

            

            

Radio buttons

            

                

                

                

            

        

    

View the example online

Enabling buttons via JavaScript

To enable buttons via JavaScript, use the JavaScript code below, where ' .nav-tabs ' is the class of the div containing the buttons.

$('.nav-tabs').button()

Method

This plugin has some methods. We will now discuss them with usage code.

$().button('toggle')



This method toggles a button's state. It gives the button its activated state and appearance. Use 'data-toggle="button"' to automatically toggle a button to the active state.

$().button('loading')



This method sets the button state to loading - that is, it disables the button and switches its text content to loading. The loading text can be defined on the button element using the 'data-loading-text' attribute.

If you use the Firefox browser, you will find that the disabled state is not automatically removed after the page loads; use 'autocomplete="off"' to avoid this problem.

$().button('reset')

This method resets the button state and restores the button's text to its original value.

$().button(string)



This method resets the button state and resets the button's text to the passed-in value.







Click here to download all the HTML, CSS, JS, and image files used in this tutorial.