Bootstrap with CSS
- Bootstrap - Responsive utilities
- Bootstrap - Helper Classes
- Bootstrap - Images
- Bootstrap - Buttons
- Bootstrap - Forms
- Bootstrap - Tables
- Bootstrap - Code
- Bootstrap - Typography
- Bootstrap - CSS Overview
- Bootstrap - Grid System
Bootstrap Layout Components
- Bootstrap - Wells
- Bootstrap - Panels
- Bootstrap - List Group
- Bootstrap - Media Object
- Bootstrap - Progress Bars
- Bootstrap - Alerts
- Bootstrap - Thumbnails
- Bootstrap - Page Header
- Bootstrap - Jumbotron
- Bootstrap - Badges
- Bootstrap - Labels
- Bootstrap - Pagination
- Bootstrap - Breadcrumb
- Bootstrap - Navbar
- Bootstrap - Navigation Elements
- Bootstrap - Input Groups
- Bootstrap - Button Dropdowns
- Bootstrap - Button Groups
- Bootstrap - Dropdowns
- Bootstrap - Glyphicons
Bootstrap Plugins
- Bootstrap - Affix Plugin
- Bootstrap - Carousel Plugin
- Bootstrap - Collapse Plugin
- Bootstrap - Button Plugin
- Bootstrap - Alert Plugin
- Bootstrap - Popover Plugin
- Bootstrap - Tooltip Plugin
- Bootstrap - Tab Plugin
- Bootstrap - Scrollspy Plugin
- Bootstrap - Dropdown Plugin
- Bootstrap - Modal Plugin
- Bootstrap - Transition Plugin
- Bootstrap - Plugins Overview
Bootstrap Demos
- Bootstrap - featured Demo
- Bootstrap - Icons Demo
- Bootstrap - Social Icons Demo
- Bootstrap - Calendar Demo
- Bootstrap - Map Demo
- Bootstrap - Caption Demo
- Bootstrap - Tabbed slider Demo
- Bootstrap - Ajax Demo
- Bootstrap - Admin Interface Demo
- Bootstrap - Alert Demo
- Bootstrap - Time line Demo
- Bootstrap - Slider Demo
- Bootstrap - Material Design Demo
- Bootstrap - Blog Demo
- Bootstrap - Navigation Demo
- Bootstrap - Responsive Demo
- Bootstrap - Images Demo
- Bootstrap - Buttons Demo
- Bootstrap - Form Demo
- Bootstrap - Table Demo
- Bootstrap - Grid Demo
Bootstrap Useful Resources
- Bootstrap - Discussion
- Bootstrap - Useful Resources
- Bootstrap - Quick Guide
- Bootstrap - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Bootstrap - Button Plugin
Buttons were explained in chapter
. With this plugin you can add in some interaction such as control button states or create groups of buttons for more components pke toolbars.If you want to include this plugin functionapty inspanidually, then you will need the button.js. Else, as mentioned in the chapter, you can include the bootstrap.js or the minified the bootstrap.min.js.
Loading State
To add a loading state to a button, simply add the data-loading-text = "Loading..." as an attribute to the button element as shown in the following example −
<button id = "fat-btn" class = "btn btn-primary" data-loading-text = "Loading..." type = "button"> Loading state </button> <script> $(function() { $(".btn").cpck(function(){ $(this).button( loading ).delay(1000).queue(function() { // $(this).button( reset ); }); }); }); </script>
When you cpck on the button the output would be as seen in the following image −
Single toggle
To activate toggpng (i.e. change the normal state of a button to a push state and vice versa) on a single button, add the data-toggle = "button" as an attribute to the button element as shown in the following example −
<button type = "button" class = "btn btn-primary" data-toggle = "button"> Single toggle </button>
Checkbox
You can create group of checkboxes and add toggpng to it by simply adding the data attribute data-toggle = "buttons" to the btn-group.
<span class = "btn-group" data-toggle = "buttons"> <label class = "btn btn-primary"> <input type = "checkbox"> Option 1 </label> <label class = "btn btn-primary"> <input type = "checkbox"> Option 2 </label> <label class = "btn btn-primary"> <input type = "checkbox"> Option 3 </label> </span>
Radio
Similarly you can create a group of radio inputs and add toggpng to it by simply adding the data attribute data-toggle = "buttons" to the btn-group.
<span class = "btn-group" data-toggle = "buttons"> <label class = "btn btn-primary"> <input type = "radio" name =" options" id = "option1"> Option 1 </label> <label class = "btn btn-primary"> <input type = "radio" name = "options" id = "option2"> Option 2 </label> <label class = "btn btn-primary"> <input type = "radio" name = "options" id = "option3"> Option 3 </label> </span>
Usage
You can enable buttons plugin via JavaScript as shown below −
$( .btn ).button()
Options
There are no options.
Methods
Given below are some of the useful methods for buttons plugin −
Method | Description | Example |
---|---|---|
button( toggle ) |
Toggles push state. Gives the button the appearance that it has been activated. You can also enable auto toggpng of a button by using the data-toggle attribute. |
$().button( toggle ) |
.button( loading ) |
When loading, the button is disabled and the text is changed to the option from the data-loading-text attribute of button element |
$().button( loading ) |
.button( reset ) |
Resets button state, bringing the original content back to the text. This method is useful when you need to return the button back to the primary state |
$().button( reset ) |
.button(string) |
String in this method is referring to any string declared by the user. To reset the button state and bring in new content use this method. |
$().button(string) |
Example
The following example demonstrates the use of the above methods −
<h2>Cpck on each of the buttons to see the effects of methods</h2> <h4>Example to demonstrate .button( toggle ) method</h4> <span id = "myButtons1" class = "bs-example"> <button type = "button" class = "btn btn-primary">Primary</button> </span> <h4>Example to demonstrate .button( loading ) method</h4> <span id = "myButtons2" class = "bs-example"> <button type = "button" class = "btn btn-primary" data-loading-text = "Loading..."> Primary </button> </span> <h4>Example to demonstrate .button( reset ) method</h4> <span id = "myButtons3" class = "bs-example"> <button type = "button" class = "btn btn-primary" data-loading-text = "Loading..."> Primary </button> </span> <h4>Example to demonstrate .button(string) method</h4> <button type = "button" class = "btn btn-primary" id = "myButton4" data-complete-text = "Loading finished"> Cpck Me </button> <script type = "text/javascript"> $(function () { $("#myButtons1 .btn").cpck(function(){ $(this).button( toggle ); }); }); $(function() { $("#myButtons2 .btn").cpck(function(){ $(this).button( loading ).delay(1000).queue(function() { }); }); }); $(function() { $("#myButtons3 .btn").cpck(function(){ $(this).button( loading ).delay(1000).queue(function() { $(this).button( reset ); }); }); }); $(function() { $("#myButton4").cpck(function(){ $(this).button( loading ).delay(1000).queue(function() { $(this).button( complete ); }); }); }); </script>Advertisements