w3resource logo

Twitter Bootstrap Button

Twitter Bootstrap Button JavaScript Plugin

Secondary Nav


Twitter Bootstrap Button JavaScript Plugin allows you to enhance functionalities of Button. You may control button states or create groups of buttons for components like toolbars.

What is required

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

How to use it

You may use this plugin only with markup, without writing any JavaScript, or you may enable buttons via JavaScript.


The first example shows how to use button plugin without any JavaScript.

	 <!DOCTYPE html>
<meta charset="utf-8" />
<title>Example of Bootstrap Button JavaScript Plugin</title>
<link href="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<div class="container">
<div class="row">
<div class="span8">
<h2>Example of Bootstrap Button JavaScript Plugin</h2>
<h3>Control state</h3>
<p><button id="fat-btn" data-loading-text="loading..." class="btn btn-primary">Loading State</button></p>
<h3>Single toggle</h3>
<p><button class="btn btn-primary" data-toggle="button">Single Toggle</button></p>
<p><div class="btn-group" data-toggle="buttons-checkbox">
                    <button class="btn btn-primary">Left</button>
                    <button class="btn btn-primary">Middle</button>
                    <button class="btn btn-primary">Right</button>
<p><div class="btn-group" data-toggle="buttons-radio">
                    <button class="btn btn-primary">Left</button>
                    <button class="btn btn-primary">Middle</button>
                    <button class="btn btn-primary">Right</button>
<!--Except 	'Control state', other buttons require only jquery.js and bootstrap-button.js JavaScript files-->			  
<script type="text/javascript" src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/jquery.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/assets/js/bootstrap-transition.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-modal.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-dropdown.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-scrollspy.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tab.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tooltip.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-popover.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-button.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-typeahead.js"></script>
<script src="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/js/application.js"></script>

View this example online.

Enable buttons via javascript

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



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


<button class="btn" data-toggle="button" >…</button>

This method implies changes the appearance of the button, and makes it look activated. Auto toggling of a button is enabled using 'data-toggle="button"'.


<button class="btn" data-loading-text="loading stuff..." >...</button>

This method Sets button state to loading. Text displayed is stored as the value of the 'data-loading-text' attribute.

If you are using Firefox, you may find that, even after the page reloads, the disabled state is unaltered. Use 'autocomplete="off"', to get rid of this.


This method resets button state by swapping text to original text.


<button class="btn" data-loading-text="loading stuff..." >...</button>

This method resets button state by swapping text to any data defined text state.

<button class="btn" data-complete-text="finished!" >...</button>

You may download all the HTML, CSS, JS and image files used in our tutorials here.

Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables