Individual or compiled

Plugins tin be included individually (using Bootstrap'south individual *.js files), or all at once (using bootstrap.js or the minified bootstrap.min.js).

Using the compiled JavaScript

Both bootstrap.js and bootstrap.min.js comprise all plugins in a single file. Include only one.

Plugin dependencies

Some plugins and CSS components depend on other plugins. If y'all include plugins individually, brand sure to check for these dependencies in the docs. Likewise notation that all plugins depend on jQuery (this ways jQuery must be included earlier the plugin files). Consult our bower.json to come across which versions of jQuery are supported.

Data attributes

Y'all tin utilize all Bootstrap plugins purely through the markup API without writing a unmarried line of JavaScript. This is Bootstrap'southward first-course API and should be your first consideration when using a plugin.

That said, in some situations it may exist desirable to turn this functionality off. Therefore, we besides provide the ability to disable the data attribute API by unbinding all events on the document namespaced with data-api. This looks like this:

                              $                (                document                ).                off                (                '.data-api'                )                          

Alternatively, to target a specific plugin, only include the plugin's name as a namespace along with the data-api namespace like this:

                              $                (                document                ).                off                (                '.alarm.information-api'                )                          

Only one plugin per element via data attributes

Don't use data attributes from multiple plugins on the aforementioned chemical element. For case, a button cannot both have a tooltip and toggle a modal. To accomplish this, utilise a wrapping chemical element.

Programmatic API

We also believe y'all should be able to utilize all Bootstrap plugins purely through the JavaScript API. All public APIs are unmarried, chainable methods, and return the collection acted upon.

                              $                (                '.btn.danger'                ).                button                (                'toggle'                ).                addClass                (                'fat'                )                          

All methods should have an optional options object, a cord which targets a particular method, or cypher (which initiates a plugin with default behavior):

                              $                (                '#myModal'                ).                modal                ()                // initialized with defaults                $                (                '#myModal'                ).                modal                ({                keyboard                :                false                })                // initialized with no keyboard                $                (                '#myModal'                ).                modal                (                'bear witness'                )                // initializes and invokes testify immediately                          

Each plugin likewise exposes its raw constructor on a Constructor property: $.fn.popover.Constructor. If y'all'd similar to get a item plugin instance, retrieve it directly from an element: $('[rel="popover"]').data('popover').

Default settings

You lot can change the default settings for a plugin by modifying the plugin's Constructor.DEFAULTS object:

                              $                .                fn                .                modal                .                Constructor                .                DEFAULTS                .                keyboard                =                fake                // changes default for the modal plugin's `keyboard` option to false                          

No conflict

Sometimes information technology is necessary to utilise Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions tin occasionally occur. If this happens, you may telephone call .noConflict on the plugin y'all wish to revert the value of.

                              var                bootstrapButton                =                $                .                fn                .                push                .                noConflict                ()                // return $.fn.push to previously assigned value                $                .                fn                .                bootstrapBtn                =                bootstrapButton                // give $().bootstrapBtn the Bootstrap functionality                          

Events

Bootstrap provides custom events for most plugins' unique actions. Mostly, these come in an infinitive and past participle form - where the infinitive (ex. show) is triggered at the start of an upshot, and its by participle form (ex. shown) is triggered on the completion of an activity.

As of 3.0.0, all Bootstrap events are namespaced.

All infinitive events provide preventDefault functionality. This provides the ability to stop the execution of an action before it starts.

                              $                (                '#myModal'                ).                on                (                'show.bs.modal'                ,                office                (                e                )                {                if                (                !                data                )                return                e                .                preventDefault                ()                // stops modal from existence shown                })                          

Sanitizer

Tooltips and Popovers utilize our built-in sanitizer to sanitize options which accept HTML.

The default whiteList value is the post-obit:

                              var                ARIA_ATTRIBUTE_PATTERN                =                /^aria-                [\w                -                ]                *$/i                var                DefaultWhitelist                =                {                // Global attributes immune on any supplied element beneath.                '*'                :                [                'form'                ,                'dir'                ,                'id'                ,                'lang'                ,                'role'                ,                ARIA_ATTRIBUTE_PATTERN                ],                a                :                [                'target'                ,                'href'                ,                'title'                ,                'rel'                ],                area                :                [],                b                :                [],                br                :                [],                col                :                [],                code                :                [],                div                :                [],                em                :                [],                60 minutes                :                [],                h1                :                [],                h2                :                [],                h3                :                [],                h4                :                [],                h5                :                [],                h6                :                [],                i                :                [],                img                :                [                'src'                ,                'alt'                ,                'title'                ,                'width'                ,                'summit'                ],                li                :                [],                ol                :                [],                p                :                [],                pre                :                [],                s                :                [],                small                :                [],                span                :                [],                sub                :                [],                sup                :                [],                strong                :                [],                u                :                [],                ul                :                []                }                          

If yous want to add together new values to this default whiteList you tin do the following:

                              var                myDefaultWhiteList                =                $                .                fn                .                tooltip                .                Constructor                .                DEFAULTS                .                whiteList                // To permit table elements                myDefaultWhiteList                .                table                =                []                // To permit td elements and data-option attributes on td elements                myDefaultWhiteList                .                td                =                [                'data-option'                ]                // You can button your custom regex to validate your attributes.                // Be conscientious most your regular expressions beingness too lax                var                myCustomRegex                =                /^data-my-app-                [\w                -                ]                +/                myDefaultWhiteList                [                '*'                ].                push button                (                myCustomRegex                )                          

If you want to bypass our sanitizer because you prefer to use a dedicated library, for example DOMPurify, you should practice the following:

                              $                (                '#yourTooltip'                ).                tooltip                ({                sanitizeFn                :                function                (                content                )                {                return                DOMPurify                .                sanitize                (                content                )                }                })                          

Browsers without document.implementation.createHTMLDocument

In instance of browsers that don't support document.implementation.createHTMLDocument, like Internet Explorer eight, the built-in sanitize function returns the HTML as is.

If yous want to perform sanitization in this instance, delight specify sanitizeFn and apply an external library like DOMPurify.

Version numbers

The version of each of Bootstrap's jQuery plugins tin can be accessed via the VERSION holding of the plugin'southward constructor. For example, for the tooltip plugin:

                              $                .                fn                .                tooltip                .                Constructor                .                VERSION                // => "3.iv.i"                          

No special fallbacks when JavaScript is disabled

Bootstrap's plugins don't autumn back specially gracefully when JavaScript is disabled. If yous care nearly the user experience in this case, utilize <noscript> to explain the state of affairs (and how to re-enable JavaScript) to your users, and/or add your ain custom fallbacks.

Third-political party libraries

Bootstrap does not officially support third-party JavaScript libraries similar Paradigm or jQuery UI. Despite .noConflict and namespaced events, there may exist compatibility problems that you demand to fix on your own.

About transitions

For simple transition effects, include transition.js in one case alongside the other JS files. If y'all're using the compiled (or minified) bootstrap.js, there is no need to include this—it'due south already in that location.

What'south inside

Transition.js is a basic helper for transitionEnd events also as a CSS transition emulator. It's used by the other plugins to check for CSS transition support and to grab hanging transitions.

Disabling transitions

Transitions can be globally disabled using the following JavaScript snippet, which must come after transition.js (or bootstrap.js or bootstrap.min.js, equally the case may be) has loaded:

                              $                .                support                .                transition                =                false                          

Modals are streamlined, but flexible, dialog prompts with the minimum required functionality and smart defaults.

Multiple open up modals non supported

Be sure not to open up a modal while another is withal visible. Showing more than one modal at a fourth dimension requires custom code.

Modal markup placement

Always try to place a modal's HTML code in a top-level position in your document to avoid other components affecting the modal's advent and/or functionality.

Due to how HTML5 defines its semantics, the autofocus HTML attribute has no effect in Bootstrap modals. To achieve the same outcome, use some custom JavaScript:

                              $                (                '#myModal'                ).                on                (                'shown.bs.modal'                ,                function                ()                {                $                (                '#myInput'                ).                focus                ()                })                          

Examples

Static example

A rendered modal with header, body, and set of actions in the footer.

                              <div                grade=                "modal fade"                tabindex=                "-ane"                part=                "dialog"                >                <div                class=                "modal-dialog"                role=                "document"                >                <div                class=                "modal-content"                >                <div                grade=                "modal-header"                >                <button                type=                "button"                class=                "close"                data-dismiss=                "modal"                aria-characterization=                "Shut"                ><bridge                aria-subconscious=                "true"                >                &times;                </span></button>                <h4                class=                "modal-title"                >Modal title</h4>                </div>                <div                course=                "modal-body"                >                <p>One fine body&hellip;                </p>                </div>                <div                class=                "modal-footer"                >                <button                type=                "button"                form=                "btn btn-default"                data-dismiss=                "modal"                >Close</button>                <button                type=                "button"                grade=                "btn btn-primary"                >Salve changes</push button>                </div>                </div>                <!-- /.modal-content -->                </div>                <!-- /.modal-dialog -->                </div>                <!-- /.modal -->                          

Live demo

Toggle a modal via JavaScript by clicking the button beneath. It volition slide down and fade in from the meridian of the folio.

                              <!-- Button trigger modal -->                <push button                blazon=                "button"                class=                "btn btn-primary btn-lg"                information-toggle=                "modal"                data-target=                "#myModal"                >                Launch demo modal                </button>                <!-- Modal -->                <div                form=                "modal fade"                id=                "myModal"                tabindex=                "-one"                function=                "dialog"                aria-labelledby=                "myModalLabel"                >                <div                class=                "modal-dialog"                function=                "document"                >                <div                class=                "modal-content"                >                <div                class=                "modal-header"                >                <button                blazon=                "button"                class=                "close"                data-dismiss=                "modal"                aria-characterization=                "Close"                ><span                aria-hidden=                "true"                >                &times;                </span></push>                <h4                class=                "modal-title"                id=                "myModalLabel"                >Modal championship</h4>                </div>                <div                course=                "modal-body"                >                ...                </div>                <div                class=                "modal-footer"                >                <button                type=                "button"                class=                "btn btn-default"                data-dismiss=                "modal"                >Close</push>                <push button                blazon=                "button"                class=                "btn btn-primary"                >Save changes</push>                </div>                </div>                </div>                </div>                          

Make modals accessible

Be sure to add role="dialog" and aria-labelledby="...", referencing the modal championship, to .modal, and role="certificate" to the .modal-dialog itself.

Additionally, you may give a description of your modal dialog with aria-describedby on .modal.

Embedding YouTube videos

Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. Run into this helpful Stack Overflow mail service for more information.

Optional sizes

Modals take 2 optional sizes, available via modifier classes to be placed on a .modal-dialog.

                              <!-- Large modal -->                <push button                type=                "push button"                class=                "btn btn-primary"                data-toggle=                "modal"                data-target=                ".bs-example-modal-lg"                >Large modal</button>                <div                class=                "modal fade"                tabindex=                "-one"                function=                "dialog"                aria-labelledby=                "myLargeModalLabel"                >                <div                class=                "modal-dialog modal-lg"                role=                "document"                >                <div                form=                "modal-content"                >                ...                </div>                </div>                </div>                <!-- Pocket-sized modal -->                <button                type=                "button"                class=                "btn btn-primary"                information-toggle=                "modal"                information-target=                ".bs-instance-modal-sm"                >Small modal</push>                <div                grade=                "modal fade"                tabindex=                "-1"                role=                "dialog"                aria-labelledby=                "mySmallModalLabel"                >                <div                grade=                "modal-dialog modal-sm"                role=                "certificate"                >                <div                class=                "modal-content"                >                ...                </div>                </div>                </div>                          

Remove animation

For modals that just announced rather than fade in to view, remove the .fade class from your modal markup.

                              <div                form=                "modal"                tabindex=                "-one"                role=                "dialog"                aria-labelledby=                "..."                >                ...                </div>                          

Using the grid system

To have advantage of the Bootstrap filigree organisation inside a modal, just nest .rows inside the .modal-body and so apply the normal grid system classes.

                              <div                class=                "modal fade"                tabindex=                "-ane"                role=                "dialog"                aria-labelledby=                "gridSystemModalLabel"                >                <div                class=                "modal-dialog"                role=                "certificate"                >                <div                form=                "modal-content"                >                <div                class=                "modal-header"                >                <push                blazon=                "button"                form=                "close"                data-dismiss=                "modal"                aria-characterization=                "Close"                ><span                aria-hidden=                "true"                >                &times;                </bridge></push button>                <h4                class=                "modal-title"                id=                "gridSystemModalLabel"                >Modal championship</h4>                </div>                <div                class=                "modal-torso"                >                <div                class=                "row"                >                <div                class=                "col-md-4"                >.col-doc-4</div>                <div                grade=                "col-md-4 col-md-offset-4"                >.col-md-iv .col-doc-offset-iv</div>                </div>                <div                form=                "row"                >                <div                form=                "col-md-iii col-doc-offset-3"                >.col-md-three .col-doctor-starting time-3</div>                <div                course=                "col-md-2 col-md-outset-4"                >.col-md-2 .col-physician-offset-four</div>                </div>                <div                class=                "row"                >                <div                class=                "col-md-6 col-md-offset-3"                >.col-dr.-6 .col-dr.-offset-3</div>                </div>                <div                class=                "row"                >                <div                class=                "col-sm-9"                >                Level ane: .col-sm-ix                <div                course=                "row"                >                <div                course=                "col-xs-viii col-sm-6"                >                Level 2: .col-xs-8 .col-sm-6                </div>                <div                form=                "col-xs-4 col-sm-half-dozen"                >                Level two: .col-xs-4 .col-sm-vi                </div>                </div>                </div>                </div>                </div>                <div                class=                "modal-footer"                >                <push button                type=                "button"                class=                "btn btn-default"                data-dismiss=                "modal"                >Close</button>                <button                type=                "button"                class=                "btn btn-chief"                >Salve changes</button>                </div>                </div>                <!-- /.modal-content -->                </div>                <!-- /.modal-dialog -->                </div>                <!-- /.modal -->                          

Take a bunch of buttons that all trigger the aforementioned modal, merely with slightly different contents? Apply event.relatedTarget and HTML information-* attributes (perchance via jQuery) to vary the contents of the modal depending on which push button was clicked. Run across the Modal Events docs for details on relatedTarget,

                              <button                type=                "button"                class=                "btn btn-principal"                information-toggle=                "modal"                data-target=                "#exampleModal"                information-whatever=                "@mdo"                >Open up modal for @mdo</button>                <button                type=                "button"                grade=                "btn btn-primary"                information-toggle=                "modal"                information-target=                "#exampleModal"                data-whatever=                "@fat"                >Open modal for @fat</push>                <button                type=                "push"                class=                "btn btn-primary"                data-toggle=                "modal"                information-target=                "#exampleModal"                information-whatsoever=                "@getbootstrap"                >Open modal for @getbootstrap</push>                ...more buttons...                <div                course=                "modal fade"                id=                "exampleModal"                tabindex=                "-ane"                part=                "dialog"                aria-labelledby=                "exampleModalLabel"                >                <div                form=                "modal-dialog"                office=                "document"                >                <div                class=                "modal-content"                >                <div                class=                "modal-header"                >                <push button                blazon=                "push button"                grade=                "close"                information-dismiss=                "modal"                aria-label=                "Close"                ><span                aria-hidden=                "true"                >                &times;                </span></push button>                <h4                class=                "modal-title"                id=                "exampleModalLabel"                >New bulletin</h4>                </div>                <div                form=                "modal-body"                >                <form>                <div                course=                "form-group"                >                <characterization                for=                "recipient-name"                form=                "control-label"                >Recipient:</label>                <input                type=                "text"                class=                "form-control"                id=                "recipient-proper noun"                >                </div>                <div                class=                "form-group"                >                <label                for=                "message-text"                class=                "command-characterization"                >Message:</label>                <textarea                form=                "course-control"                id=                "message-text"                ></textarea>                </div>                </form>                </div>                <div                class=                "modal-footer"                >                <button                type=                "button"                class=                "btn btn-default"                data-dismiss=                "modal"                >Shut</button>                <button                blazon=                "button"                class=                "btn btn-primary"                >Send message</button>                </div>                </div>                </div>                </div>                          
                              $                (                '#exampleModal'                ).                on                (                'show.bs.modal'                ,                function                (                issue                )                {                var                button                =                $                (                consequence                .                relatedTarget                )                // Button that triggered the modal                var                recipient                =                button                .                data                (                'whatever'                )                // Excerpt info from data-* attributes                // If necessary, you could initiate an AJAX request here (and so do the updating in a callback).                // Update the modal'south content. Nosotros'll apply jQuery here, but you lot could use a data binding library or other methods instead.                var                modal                =                $                (                this                )                modal                .                observe                (                '.modal-title'                ).                text                (                'New bulletin to '                +                recipient                )                modal                .                observe                (                '.modal-body input'                ).                val                (                recipient                )                })                          

Usage

The modal plugin toggles your subconscious content on demand, via data attributes or JavaScript. It also adds .modal-open to the <body> to override default scrolling behavior and generates a .modal-properties to provide a click area for dismissing shown modals when clicking outside the modal.

Via information attributes

Activate a modal without writing JavaScript. Ready data-toggle="modal" on a controller element, like a button, along with a information-target="#foo" or href="#foo" to target a specific modal to toggle.

                              <button                type=                "push"                data-toggle=                "modal"                data-target=                "#myModal"                >Launch modal</push button>                          

Via JavaScript

Call a modal with id myModal with a single line of JavaScript:

                              $                (                '#myModal'                ).                modal                (                options                )                          

Options

Options can exist passed via information attributes or JavaScript. For data attributes, append the choice name to data-, equally in information-backdrop="".

Name blazon default clarification
backdrop boolean or the string 'static' true Includes a modal-properties chemical element. Alternatively, specify static for a properties which doesn't close the modal on click.
keyboard boolean truthful Closes the modal when escape key is pressed
show boolean true Shows the modal when initialized.
remote path false

This option is deprecated since v3.3.0 and has been removed in v4. We recommend instead using client-side templating or a data binding framework, or calling jQuery.load yourself.

If a remote URL is provided, content will be loaded 1 time via jQuery's load method and injected into the .modal-content div. If you're using the information-api, yous may alternatively use the href attribute to specify the remote source. An example of this is shown below:

                                                  <a                          data-toggle=                          "modal"                          href=                          "remote.html"                          data-target=                          "#modal"                          >Click me</a>                                              

Methods

.modal(options)

Activates your content every bit a modal. Accepts an optional options object.

                              $                (                '#myModal'                ).                modal                ({                keyboard                :                false                })                          

.modal('toggle')

Manually toggles a modal. Returns to the caller before the modal has actually been shown or subconscious (i.due east. before the shown.bs.modal or hidden.bs.modal result occurs).

                              $                (                '#myModal'                ).                modal                (                'toggle'                )                          

.modal('testify')

Manually opens a modal. Returns to the caller before the modal has actually been shown (i.east. before the shown.bs.modal event occurs).

                              $                (                '#myModal'                ).                modal                (                'evidence'                )                          

.modal('hibernate')

Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. earlier the hidden.bs.modal event occurs).

                              $                (                '#myModal'                ).                modal                (                'hide'                )                          

.modal('handleUpdate')

Readjusts the modal's positioning to counter a scrollbar in instance i should appear, which would make the modal leap to the left.

Only needed when the elevation of the modal changes while information technology is open.

                              $                (                '#myModal'                ).                modal                (                'handleUpdate'                )                          

Events

Bootstrap'due south modal class exposes a few events for hooking into modal functionality.

All modal events are fired at the modal itself (i.due east. at the <div class="modal">).

Outcome Type Description
show.bs.modal This event fires immediately when the evidence instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the effect.
shown.bs.modal This event is fired when the modal has been made visible to the user (will look for CSS transitions to complete). If caused by a click, the clicked element is available as the relatedTarget property of the event.
hide.bs.modal This consequence is fired immediately when the hide instance method has been chosen.
hidden.bs.modal This event is fired when the modal has finished beingness hidden from the user (will wait for CSS transitions to consummate).
loaded.bs.modal This event is fired when the modal has loaded content using the remote option.
                              $                (                '#myModal'                ).                on                (                'subconscious.bs.modal'                ,                role                (                east                )                {                // practise something...                })                          

Add together dropdown menus to nearly annihilation with this simple plugin, including the navbar, tabs, and pills.

Within a navbar

Within pills

Via data attributes or JavaScript, the dropdown plugin toggles subconscious content (dropdown menus) by toggling the .open class on the parent list item.

On mobile devices, opening a dropdown adds a .dropdown-backdrop equally a tap area for closing dropdown menus when tapping outside the menu, a requirement for proper iOS support. This means that switching from an open dropdown menu to a different dropdown carte du jour requires an actress tap on mobile.

Note: The data-toggle="dropdown" attribute is relied on for closing dropdown menus at an application level, so it's a good thought to always use it.

Via data attributes

Add together information-toggle="dropdown" to a link or push button to toggle a dropdown.

                              <div                class=                "dropdown"                >                <button                id=                "dLabel"                type=                "button"                information-toggle=                "dropdown"                aria-haspopup=                "true"                aria-expanded=                "false"                >                Dropdown trigger                <span                class=                "caret"                ></span>                </button>                <ul                form=                "dropdown-bill of fare"                aria-labelledby=                "dLabel"                >                ...                </ul>                </div>                          

To continue URLs intact with link buttons, use the data-target aspect instead of href="#".

                              <div                class=                "dropdown"                >                <a                id=                "dLabel"                data-target=                "#"                href=                "http://case.com/"                data-toggle=                "dropdown"                office=                "push"                aria-haspopup=                "truthful"                aria-expanded=                "faux"                >                Dropdown trigger                <span                class=                "caret"                ></span>                </a>                <ul                grade=                "dropdown-menu"                aria-labelledby=                "dLabel"                >                ...                </ul>                </div>                          

Via JavaScript

Call the dropdowns via JavaScript:

                              $                (                '.dropdown-toggle'                ).                dropdown                ()                          

data-toggle="dropdown" notwithstanding required

Regardless of whether y'all call your dropdown via JavaScript or instead utilise the data-api, data-toggle="dropdown" is always required to be present on the dropdown's trigger element.

None

$().dropdown('toggle')

Toggles the dropdown menu of a given navbar or tabbed navigation.

All dropdown events are fired at the .dropdown-carte's parent element.

All dropdown events take a relatedTarget holding, whose value is the toggling anchor element.

Event Type Description
show.bs.dropdown This outcome fires immediately when the show instance method is called.
shown.bs.dropdown This event is fired when the dropdown has been fabricated visible to the user (will wait for CSS transitions, to complete).
hide.bs.dropdown This upshot is fired immediately when the hibernate instance method has been called.
subconscious.bs.dropdown This outcome is fired when the dropdown has finished existence hidden from the user (will wait for CSS transitions, to complete).
                              $                (                '#myDropdown'                ).                on                (                'testify.bs.dropdown'                ,                part                ()                {                // exercise something…                })                          

The ScrollSpy plugin is for automatically updating nav targets based on scroll position. Scroll the surface area beneath the navbar and spotter the agile class change. The dropdown sub items will be highlighted as well.

Requires relative positioning

No matter the implementation method, scrollspy requires the use of position: relative; on the element you're spying on. In most cases this is the <body>. When scrollspying on elements other than the <body>, be sure to accept a height set and overflow-y: scroll; practical.

Via information attributes

To hands add scrollspy behavior to your topbar navigation, add together data-spy="scroll" to the element you want to spy on (near typically this would be the <torso>). So add the data-target attribute with the ID or class of the parent element of whatever Bootstrap .nav component.

                              body                {                position                :                relative                ;                }                          
                              <trunk                data-spy=                "scroll"                data-target=                "#navbar-example"                >                ...                <div                id=                "navbar-example"                >                <ul                class=                "nav nav-tabs"                role=                "tablist"                >                ...                </ul>                </div>                ...                </body>                          

Via JavaScript

Later on adding position: relative; in your CSS, call the scrollspy via JavaScript:

                              $                (                'torso'                ).                scrollspy                ({                target                :                '#navbar-example'                })                          

Methods

.scrollspy('refresh')

When using scrollspy in conjunction with calculation or removing of elements from the DOM, y'all'll need to phone call the refresh method like so:

                              $                (                '[information-spy="whorl"]'                ).                each                (                role                ()                {                var                $spy                =                $                (                this                ).                scrollspy                (                'refresh'                )                })                          

Options

Options tin be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in information-get-go="".

Name type default description
offset number ten Pixels to kickoff from top when calculating position of coil.

Events

Event Type Description
activate.bs.scrollspy This event fires whenever a new item becomes activated by the scrollspy.
                              $                (                '#myScrollspy'                ).                on                (                'activate.bs.scrollspy'                ,                function                ()                {                // practice something…                })                          

Example tabs

Add quick, dynamic tab functionality to transition through panes of local content, fifty-fifty via dropdown menus. Nested tabs are not supported.

Raw denim you lot probably oasis't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth principal cleanse. Mustache platitude tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.

Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin java squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table arts and crafts beer twee. Qui photograph booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-chip, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Fine art political party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.

Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-tabular array readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid eight-scrap cred pitchfork. Williamsburg banh mi whatever gluten-costless, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you lot probably haven't heard of them, vinyl craft beer weblog stumptown. Pitchfork sustainable tofu synth chambray yr.

Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art political party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche loftier life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.

Usage

Enable tabbable tabs via JavaScript (each tab needs to be activated individually):

                              $                (                '#myTabs a'                ).                click                (                function                (                e                )                {                e                .                preventDefault                ()                $                (                this                ).                tab                (                'show'                )                })                          

Y'all can actuate individual tabs in several ways:

                              $                (                '#myTabs a[href="#profile"]'                ).                tab                (                'prove'                )                // Select tab by name                $                (                '#myTabs a:kickoff'                ).                tab                (                'show'                )                // Select first tab                $                (                '#myTabs a:last'                ).                tab                (                'show'                )                // Select last tab                $                (                '#myTabs li:eq(2) a'                ).                tab                (                'show'                )                // Select tertiary tab (0-indexed)                          

Markup

You can actuate a tab or pill navigation without writing whatsoever JavaScript past simply specifying data-toggle="tab" or information-toggle="pill" on an element. Calculation the nav and nav-tabs classes to the tab ul will apply the Bootstrap tab styling, while calculation the nav and nav-pills classes will apply pill styling.

                              <div>                <!-- Nav tabs -->                <ul                class=                "nav nav-tabs"                part=                "tablist"                >                <li                role=                "presentation"                class=                "active"                ><a                href=                "#home"                aria-controls=                "home"                part=                "tab"                information-toggle=                "tab"                >Domicile</a></li>                <li                role=                "presentation"                ><a                href=                "#profile"                aria-controls=                "profile"                role=                "tab"                data-toggle=                "tab"                >Profile</a></li>                <li                role=                "presentation"                ><a                href=                "#messages"                aria-controls=                "messages"                function=                "tab"                data-toggle=                "tab"                >Letters</a></li>                <li                role=                "presentation"                ><a                href=                "#settings"                aria-controls=                "settings"                role=                "tab"                data-toggle=                "tab"                >Settings</a></li>                </ul>                <!-- Tab panes -->                <div                class=                "tab-content"                >                <div                role=                "tabpanel"                class=                "tab-pane active"                id=                "dwelling"                >...</div>                <div                role=                "tabpanel"                grade=                "tab-pane"                id=                "profile"                >...</div>                <div                role=                "tabpanel"                form=                "tab-pane"                id=                "letters"                >...</div>                <div                part=                "tabpanel"                form=                "tab-pane"                id=                "settings"                >...</div>                </div>                </div>                          

Fade event

To make tabs fade in, add .fade to each .tab-pane. The first tab pane must also have .in to make the initial content visible.

                              <div                grade=                "tab-content"                >                <div                role=                "tabpanel"                form=                "tab-pane fade in active"                id=                "home"                >...</div>                <div                role=                "tabpanel"                grade=                "tab-pane fade"                id=                "contour"                >...</div>                <div                role=                "tabpanel"                class=                "tab-pane fade"                id=                "messages"                >...</div>                <div                role=                "tabpanel"                class=                "tab-pane fade"                id=                "settings"                >...</div>                </div>                          

Methods

$().tab

Activates a tab element and content container. Tab should take either a data-target or an href targeting a container node in the DOM. In the to a higher place examples, the tabs are the <a>due south with information-toggle="tab" attributes.

.tab('evidence')

Selects the given tab and shows its associated content. Whatever other tab that was previously selected becomes unselected and its associated content is hidden. Returns to the caller before the tab pane has actually been shown (i.e. before the shown.bs.tab event occurs).

                              $                (                '#someTab'                ).                tab                (                'show'                )                          

Events

When showing a new tab, the events fire in the following lodge:

  1. hide.bs.tab (on the current agile tab)
  2. testify.bs.tab (on the to-be-shown tab)
  3. subconscious.bs.tab (on the previous agile tab, the same one every bit for the hide.bs.tab event)
  4. shown.bs.tab (on the newly-active just-shown tab, the same one as for the show.bs.tab event)

If no tab was already active, so the hibernate.bs.tab and subconscious.bs.tab events volition not be fired.

Event Type Description
show.bs.tab This upshot fires on tab show, just before the new tab has been shown. Use event.target and outcome.relatedTarget to target the active tab and the previous active tab (if bachelor) respectively.
shown.bs.tab This event fires on tab evidence subsequently a tab has been shown. Use event.target and event.relatedTarget to target the agile tab and the previous active tab (if available) respectively.
hide.bs.tab This outcome fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use upshot.target and event.relatedTarget to target the electric current active tab and the new soon-to-be-active tab, respectively.
subconscious.bs.tab This upshot fires after a new tab is shown (and thus the previous active tab is hidden). Utilize event.target and event.relatedTarget to target the previous active tab and the new active tab, respectively.
                              $                (                'a[data-toggle="tab"]'                ).                on                (                'shown.bs.tab'                ,                function                (                e                )                {                e                .                target                // newly activated tab                e                .                relatedTarget                // previous active tab                })                          

Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don't rely on images, use CSS3 for animations, and data-attributes for local title storage.

Tooltips with zero-length titles are never displayed.

Hover over the links below to see tooltips:

Tight pants next level keffiyeh you probably haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney'southward fixie sustainable quinoa 8-bit american apparel have a terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A really ironic artisan any keytar, scenester farm-to-table banksy Austin twitter handle freegan cred raw denim single-origin coffee viral.

Static tooltip

Four options are available: summit, right, lesser, and left aligned.

4 directions

                              <button                type=                "push"                class=                "btn btn-default"                data-toggle=                "tooltip"                data-placement=                "left"                championship=                "Tooltip on left"                >Tooltip on left</button>                <push                blazon=                "button"                course=                "btn btn-default"                information-toggle=                "tooltip"                data-placement=                "top"                title=                "Tooltip on top"                >Tooltip on top</push button>                <button                type=                "button"                class=                "btn btn-default"                data-toggle=                "tooltip"                data-placement=                "bottom"                title=                "Tooltip on bottom"                >Tooltip on bottom</button>                <button                blazon=                "push"                class=                "btn btn-default"                information-toggle=                "tooltip"                data-placement=                "right"                championship=                "Tooltip on right"                >Tooltip on right</button>                          

The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element.

Trigger the tooltip via JavaScript:

                              $                (                '#case'                ).                tooltip                (                options                )                          

Markup

The required markup for a tooltip is only a data aspect and title on the HTML element you lot wish to have a tooltip. The generated markup of a tooltip is rather simple, though it does require a position (by default, set to top past the plugin).

                              <!-- HTML to write -->                <a                href=                "#"                data-toggle=                "tooltip"                championship=                "Some tooltip text!"                >Hover over me</a>                <!-- Generated markup by the plugin -->                <div                grade=                "tooltip acme"                part=                "tooltip"                >                <div                course=                "tooltip-arrow"                ></div>                <div                class=                "tooltip-inner"                >                Some tooltip text!                </div>                </div>                          

Options

Options can be passed via data attributes or JavaScript. For information attributes, append the option proper name to data-, as in information-animation="".

Note that for security reasons the sanitize, sanitizeFn and whiteList options cannot be supplied using data attributes.

Name Type Default Description
animation boolean true Utilise a CSS fade transition to the tooltip
container string | false false

Appends the tooltip to a specific chemical element. Case: container: 'torso'. This option is particularly useful in that it allows you to position the tooltip in the menstruum of the document near the triggering chemical element - which will foreclose the tooltip from floating away from the triggering element during a window resize.

delay number | object 0

Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type

If a number is supplied, delay is applied to both hide/show

Object construction is: delay: { "show": 500, "hide": 100 }

html boolean false Insert HTML into the tooltip. If false, jQuery's text method will exist used to insert content into the DOM. Use text if you're worried about XSS attacks.
placement string | office 'top'

How to position the tooltip - top | bottom | left | correct | auto.
When "motorcar" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display correct.

When a function is used to decide the placement, it is chosen with the tooltip DOM node as its first argument and the triggering chemical element DOM node every bit its 2d. The this context is fix to the tooltip instance.

selector string false If a selector is provided, tooltip objects will be delegated to the specified targets. In do, this is used to also apply tooltips to dynamically added DOM elements (jQuery.on support). See this and an informative example.
template string '<div class="tooltip" part="tooltip"><div form="tooltip-pointer"></div><div class="tooltip-inner"></div></div>'

Base HTML to use when creating the tooltip.

The tooltip's title will be injected into the .tooltip-inner.

.tooltip-arrow will go the tooltip's arrow.

The outermost wrapper element should have the .tooltip class.

title cord | function ''

Default title value if title attribute isn't present.

If a part is given, it will be chosen with its this reference set to the chemical element that the tooltip is attached to.

trigger string 'hover focus' How tooltip is triggered - click | hover | focus | manual. You may laissez passer multiple triggers; separate them with a space. manual cannot be combined with any other trigger.
viewport string | object | function { selector: 'body', padding: 0 }

Keeps the tooltip within the premises of this chemical element. Example: viewport: '#viewport' or { "selector": "#viewport", "padding": 0 }

If a office is given, it is chosen with the triggering chemical element DOM node as its only argument. The this context is set to the tooltip instance.

sanitize boolean true Enable or disable the sanitization. If activated 'template', 'content' and 'championship' options will be sanitized.
whiteList object Default value Object which contains allowed attributes and tags
sanitizeFn zippo | function nix Here you can supply your own sanitize function. This tin exist useful if you prefer to use a dedicated library to perform sanitization.

Methods

$().tooltip(options)

Attaches a tooltip handler to an element collection.

.tooltip('show')

Reveals an element's tooltip. Returns to the caller earlier the tooltip has actually been shown (i.e. before the shown.bs.tooltip event occurs). This is considered a "transmission" triggering of the tooltip. Tooltips with zero-length titles are never displayed.

                              $                (                '#element'                ).                tooltip                (                'show'                )                          

.tooltip('hide')

Hides an element's tooltip. Returns to the caller before the tooltip has really been hidden (i.east. before the hidden.bs.tooltip effect occurs). This is considered a "manual" triggering of the tooltip.

                              $                (                '#element'                ).                tooltip                (                'hibernate'                )                          

.tooltip('toggle')

Toggles an element'south tooltip. Returns to the caller before the tooltip has actually been shown or subconscious (i.e. earlier the shown.bs.tooltip or hidden.bs.tooltip event occurs). This is considered a "manual" triggering of the tooltip.

                              $                (                '#element'                ).                tooltip                (                'toggle'                )                          

.tooltip('destroy')

Hides and destroys an element's tooltip. Tooltips that utilize delegation (which are created using the selector option) cannot be individually destroyed on descendant trigger elements.

                              $                (                '#chemical element'                ).                tooltip                (                'destroy'                )                          

Events

Event Type Description
bear witness.bs.tooltip This event fires immediately when the show instance method is called.
shown.bs.tooltip This event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete).
hide.bs.tooltip This event is fired immediately when the hide instance method has been called.
hidden.bs.tooltip This effect is fired when the tooltip has finished being hidden from the user (volition wait for CSS transitions to complete).
inserted.bs.tooltip This event is fired after the show.bs.tooltip issue when the tooltip template has been added to the DOM.
                              $                (                '#myTooltip'                ).                on                (                'hidden.bs.tooltip'                ,                role                ()                {                // exercise something…                })                          

Add small overlays of content, like those on the iPad, to any element for housing secondary information.

Popovers whose both title and content are zero-length are never displayed.

Opt-in functionality

For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning you must initialize them yourself.

One mode to initialize all popovers on a page would be to select them past their data-toggle attribute:

                                  $                  (                  function                  ()                  {                  $                  (                  '[data-toggle="popover"]'                  ).                  popover                  ()                  })                              

Popovers in push button groups, input groups, and tables require special setting

When using popovers on elements within a .btn-group or an .input-grouping, or on table-related elements (<td>, <th>, <tr>, <thead>, <tbody>, <tfoot>), you lot'll take to specify the option container: 'trunk' (documented below) to avert unwanted side effects (such as the element growing wider and/or losing its rounded corners when the popover is triggered).

Popovers on disabled elements require wrapper elements

To add together a popover to a disabled or .disabled chemical element, put the element within of a <div> and utilise the popover to that <div> instead.

Multiple-line links

Sometimes you desire to add a popover to a hyperlink that wraps multiple lines. The default behavior of the popover plugin is to center it horizontally and vertically. Add together white-infinite: nowrap; to your anchors to avoid this.

Examples

Static popover

Four options are available: pinnacle, correct, bottom, and left aligned.

Popover superlative

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover correct

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover bottom

Sed posuere consectetur est at lobortis. Aenean european union leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover left

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Live demo

                              <button                type=                "button"                class=                "btn btn-lg btn-danger"                information-toggle=                "popover"                title=                "Popover title"                data-content=                "And here's some amazing content. Information technology'due south very engaging. Right?"                >Click to toggle popover</push button>                          

4 directions

                              <button                type=                "button"                class=                "btn btn-default"                data-container=                "body"                data-toggle=                "popover"                data-placement=                "left"                information-content=                "Vivamus sagittis lacus vel augue laoreet rutrum faucibus."                >                Popover on left                </button>                <button                type=                "push button"                course=                "btn btn-default"                information-container=                "body"                data-toggle=                "popover"                data-placement=                "top"                information-content=                "Vivamus sagittis lacus vel augue laoreet rutrum faucibus."                >                Popover on summit                </push>                <button                blazon=                "button"                class=                "btn btn-default"                information-container=                "body"                data-toggle=                "popover"                data-placement=                "bottom"                data-content=                "Vivamus sagittis lacus vel augue laoreet rutrum faucibus."                >                Popover on lesser                </push button>                <push                type=                "push button"                form=                "btn btn-default"                data-container=                "body"                data-toggle=                "popover"                data-placement=                "correct"                information-content=                "Vivamus sagittis lacus vel augue laoreet rutrum faucibus."                >                Popover on right                </button>                          

Dismiss on next click

Utilise the focus trigger to dismiss popovers on the next click that the user makes.

Specific markup required for dismiss-on-next-click

For proper cross-browser and cross-platform behavior, yous must use the <a> tag, not the <push> tag, and you also must include the part="push button" and tabindex attributes.

                              <a                tabindex=                "0"                class=                "btn btn-lg btn-danger"                part=                "push button"                data-toggle=                "popover"                data-trigger=                "focus"                championship=                "Dismissible popover"                data-content=                "And here's some amazing content. It's very engaging. Correct?"                >Dismissible popover</a>                          

Usage

Enable popovers via JavaScript:

                              $                (                '#instance'                ).                popover                (                options                )                          

Options

Options can be passed via information attributes or JavaScript. For data attributes, append the option name to information-, every bit in data-animation="".

Note that for security reasons the sanitize, sanitizeFn and whiteList options cannot be supplied using data attributes.

Name Type Default Description
animation boolean truthful Apply a CSS fade transition to the popover
container string | simulated false

Appends the popover to a specific element. Instance: container: 'body'. This option is specially useful in that it allows yous to position the popover in the flow of the document near the triggering element - which volition prevent the popover from floating away from the triggering element during a window resize.

content string | function ''

Default content value if data-content attribute isn't nowadays.

If a function is given, it will be called with its this reference set to the element that the popover is attached to.

delay number | object 0

Filibuster showing and hiding the popover (ms) - does not apply to manual trigger type

If a number is supplied, delay is applied to both hide/show

Object structure is: filibuster: { "prove": 500, "hide": 100 }

html boolean false Insert HTML into the popover. If faux, jQuery's text method volition be used to insert content into the DOM. Use text if you're worried near XSS attacks.
placement string | function 'right'

How to position the popover - pinnacle | bottom | left | right | car.
When "auto" is specified, it volition dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right.

When a function is used to determine the placement, it is called with the popover DOM node as its first argument and the triggering element DOM node as its second. The this context is gear up to the popover case.

selector string imitation If a selector is provided, popover objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to take popovers added. See this and an informative example.
template string '<div class="popover" function="tooltip"><div grade="arrow"></div><h3 grade="popover-title"></h3><div course="popover-content"></div></div>'

Base HTML to use when creating the popover.

The popover'south championship volition be injected into the .popover-title.

The popover'due south content volition be injected into the .popover-content.

.arrow will get the popover's arrow.

The outermost wrapper chemical element should have the .popover class.

title cord | function ''

Default title value if championship attribute isn't nowadays.

If a office is given, information technology will be called with its this reference set up to the element that the popover is attached to.

trigger string 'click' How popover is triggered - click | hover | focus | manual. Yous may pass multiple triggers; separate them with a space. transmission cannot be combined with any other trigger.
viewport cord | object | part { selector: 'body', padding: 0 }

Keeps the popover within the bounds of this element. Example: viewport: '#viewport' or { "selector": "#viewport", "padding": 0 }

If a function is given, it is called with the triggering element DOM node as its only argument. The this context is set to the popover instance.

sanitize boolean true Enable or disable the sanitization. If activated 'template', 'content' and 'title' options will be sanitized.
whiteList object Default value Object which contains allowed attributes and tags
sanitizeFn null | function zilch Here you tin supply your own sanitize function. This can be useful if yous prefer to use a dedicated library to perform sanitization.

Data attributes for individual popovers

Options for private popovers can alternatively be specified through the utilise of data attributes, as explained higher up.

Methods

$().popover(options)

Initializes popovers for an chemical element drove.

.popover('bear witness')

Reveals an element's popover. Returns to the caller before the popover has actually been shown (i.e. before the shown.bs.popover event occurs). This is considered a "manual" triggering of the popover. Popovers whose both title and content are zero-length are never displayed.

                              $                (                '#element'                ).                popover                (                'testify'                )                          

.popover('hide')

Hides an element's popover. Returns to the caller before the popover has actually been hidden (i.e. earlier the hidden.bs.popover event occurs). This is considered a "manual" triggering of the popover.

                              $                (                '#element'                ).                popover                (                'hide'                )                          

.popover('toggle')

Toggles an chemical element's popover. Returns to the caller earlier the popover has actually been shown or hidden (i.e. before the shown.bs.popover or hidden.bs.popover event occurs). This is considered a "manual" triggering of the popover.

                              $                (                '#element'                ).                popover                (                'toggle'                )                          

.popover('destroy')

Hides and destroys an element'due south popover. Popovers that utilise delegation (which are created using the selector option) cannot be individually destroyed on descendant trigger elements.

                              $                (                '#element'                ).                popover                (                'destroy'                )                          

Events

Effect Blazon Clarification
show.bs.popover This issue fires immediately when the testify instance method is called.
shown.bs.popover This consequence is fired when the popover has been made visible to the user (will wait for CSS transitions to consummate).
hide.bs.popover This outcome is fired immediately when the hide instance method has been called.
hidden.bs.popover This event is fired when the popover has finished being hidden from the user (will await for CSS transitions to consummate).
inserted.bs.popover This event is fired after the testify.bs.popover upshot when the popover template has been added to the DOM.
                              $                (                '#myPopover'                ).                on                (                'hidden.bs.popover'                ,                office                ()                {                // do something…                })                          

Example alerts

Add dismiss functionality to all warning letters with this plugin.

When using a .close button, it must be the first kid of the .alert-dismissible and no text content may come up before information technology in the markup.

Usage

But add data-dismiss="alert" to your close push button to automatically give an alert close functionality. Closing an alert removes it from the DOM.

                              <button                type=                "button"                class=                "close"                data-dismiss=                "alert"                aria-label=                "Close"                >                <span                aria-hidden=                "true"                >                &times;                </span>                </button>                          

To accept your alerts use animation when closing, make sure they have the .fade and .in classes already applied to them.

Methods

$().alert()

Makes an alarm listen for click events on descendant elements which have the data-dismiss="alarm" attribute. (Not necessary when using the information-api's automobile-initialization.)

$().alert('shut')

Closes an alert by removing it from the DOM. If the .fade and .in classes are present on the element, the alert will fade out before it is removed.

Events

Bootstrap'due south warning plugin exposes a few events for hooking into alert functionality.

Effect Type Description
close.bs.alert This consequence fires immediately when the shut instance method is chosen.
airtight.bs.warning This event is fired when the alarm has been airtight (will await for CSS transitions to consummate).
                              $                (                '#myAlert'                ).                on                (                'airtight.bs.alert'                ,                function                ()                {                // do something…                })                          

Exercise more than with buttons. Control button states or create groups of buttons for more components like toolbars.

Stateful

Add information-loading-text="Loading..." to use a loading state on a push.

This characteristic is deprecated since v3.3.5 and has been removed in v4.

Employ whichever state you like!

For the sake of this demonstration, we are using data-loading-text and $().button('loading'), but that's non the just state yous can use. Come across more on this below in the $().push(string) documentation.

                              <button                type=                "push"                id=                "myButton"                data-loading-text=                "Loading..."                class=                "btn btn-primary"                >                Loading state                </push button>                <script>                $                (                '#myButton'                ).                on                (                'click'                ,                function                ()                {                var                $btn                =                $                (                this                ).                button                (                'loading'                )                // business logic...                $btn                .                button                (                'reset'                )                })                </script>                          

Single toggle

Add data-toggle="button" to activate toggling on a single push.

Pre-toggled buttons need .agile and aria-pressed="true"

For pre-toggled buttons, you lot must add the .active class and the aria-pressed="true" attribute to the button yourself.

                              <button                type=                "push"                class=                "btn btn-main"                data-toggle=                "button"                aria-pressed=                "false"                >                Unmarried toggle                </button>                          

Checkbox / Radio

Add data-toggle="buttons" to a .btn-group containing checkbox or radio inputs to enable toggling in their respective styles.

Preselected options need .agile

For preselected options, you must add the .active course to the input'south label yourself.

Visual checked state only updated on click

If the checked country of a checkbox push button is updated without firing a click event on the button (east.g. via <input type="reset"> or via setting the checked property of the input), you will demand to toggle the .agile class on the input'south label yourself.

                              <div                class=                "btn-grouping"                data-toggle=                "buttons"                >                <characterization                class=                "btn btn-main active"                >                <input                type=                "checkbox"                checked                >                Checkbox 1 (pre-checked)                </label>                <label                form=                "btn btn-primary"                >                <input                blazon=                "checkbox"                >                Checkbox ii                </characterization>                <label                form=                "btn btn-main"                >                <input                type=                "checkbox"                >                Checkbox iii                </label>                </div>                          

                              <div                class=                "btn-grouping"                information-toggle=                "buttons"                >                <label                class=                "btn btn-primary active"                >                <input                type=                "radio"                name=                "options"                id=                "option1"                checked                >                Radio ane (preselected)                </characterization>                <label                class=                "btn btn-primary"                >                <input                type=                "radio"                name=                "options"                id=                "option2"                >                Radio 2                </characterization>                <label                class=                "btn btn-chief"                >                <input                blazon=                "radio"                name=                "options"                id=                "option3"                >                Radio 3                </label>                </div>                          

Methods

$().button('toggle')

Toggles push button state. Gives the button the appearance that information technology has been activated.

$().push('reset')

Resets button state - swaps text to original text. This method is asynchronous and returns before the resetting has actually completed.

$().button(string)

Swaps text to any data defined text state.

                              <push                blazon=                "button"                id=                "myStateButton"                data-complete-text=                "finished!"                grade=                "btn btn-principal"                >                ...                </push button>                <script>                $                (                '#myStateButton'                ).                on                (                'click'                ,                function                ()                {                $                (                this                ).                button                (                'complete'                )                // button text will be "finished!"                })                </script>                          

Flexible plugin that utilizes a scattering of classes for easy toggle behavior.

Plugin dependency

Collapse requires the transitions plugin to exist included in your version of Bootstrap.

Case

Click the buttons below to show and hibernate another element via class changes:

  • .plummet hides content
  • .collapsing is applied during transitions
  • .plummet.in shows content

You can apply a link with the href attribute, or a push button with the data-target attribute. In both cases, the data-toggle="collapse" is required.

Link with href

Anim pariatur platitude reprehenderit, enim eiusmod loftier life accusamus terry richardson advert squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.

                              <a                class=                "btn btn-primary"                role=                "button"                data-toggle=                "collapse"                href=                "#collapseExample"                aria-expanded=                "faux"                aria-controls=                "collapseExample"                >                Link with href                </a>                <button                form=                "btn btn-primary"                type=                "push"                information-toggle=                "collapse"                data-target=                "#collapseExample"                aria-expanded=                "false"                aria-controls=                "collapseExample"                >                Push button with data-target                </button>                <div                course=                "collapse"                id=                "collapseExample"                >                <div                class=                "well"                >                ...                </div>                </div>                          

Accordion case

Extend the default plummet beliefs to create an accordion with the panel component.

Collapsible Group Item #i

Anim pariatur platitude reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. three wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Advertising vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt y'all probably oasis't heard of them accusamus labore sustainable VHS.

Collapsible Group Item #two

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. iii wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on information technology squid single-origin java nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat arts and crafts beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

Collapsible Grouping Item #3

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson advert squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Advertising vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably oasis't heard of them accusamus labore sustainable VHS.

                              <div                class=                "console-group"                id=                "piano accordion"                role=                "tablist"                aria-multiselectable=                "truthful"                >                <div                class=                "console console-default"                >                <div                form=                "console-heading"                function=                "tab"                id=                "headingOne"                >                <h4                class=                "panel-title"                >                <a                role=                "button"                data-toggle=                "collapse"                information-parent=                "#squeeze box"                href=                "#collapseOne"                aria-expanded=                "true"                aria-controls=                "collapseOne"                >                Collapsible Grouping Detail #one                </a>                </h4>                </div>                <div                id=                "collapseOne"                class=                "panel-collapse collapse in"                role=                "tabpanel"                aria-labelledby=                "headingOne"                >                <div                class=                "console-body"                >                Anim pariatur cliché reprehenderit, enim eiusmod loftier life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Advertising vegan excepteur butcher vice lomo. Leggings occaecat arts and crafts beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.                </div>                </div>                </div>                <div                class=                "panel console-default"                >                <div                class=                "panel-heading"                part=                "tab"                id=                "headingTwo"                >                <h4                class=                "panel-title"                >                <a                class=                "collapsed"                role=                "button"                data-toggle=                "collapse"                data-parent=                "#squeeze box"                href=                "#collapseTwo"                aria-expanded=                "fake"                aria-controls=                "collapseTwo"                >                Collapsible Group Item #two                </a>                </h4>                </div>                <div                id=                "collapseTwo"                class=                "console-collapse collapse"                role=                "tabpanel"                aria-labelledby=                "headingTwo"                >                <div                class=                "panel-body"                >                Anim pariatur cliche reprehenderit, enim eiusmod loftier life accusamus terry richardson advertizement squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Nutrient truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin java nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-tabular array, raw denim artful synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.                </div>                </div>                </div>                <div                form=                "console panel-default"                >                <div                class=                "panel-heading"                role=                "tab"                id=                "headingThree"                >                <h4                class=                "panel-title"                >                <a                class=                "collapsed"                role=                "button"                information-toggle=                "collapse"                information-parent=                "#piano accordion"                href=                "#collapseThree"                aria-expanded=                "imitation"                aria-controls=                "collapseThree"                >                Collapsible Group Item #3                </a>                </h4>                </div>                <div                id=                "collapseThree"                class=                "console-collapse collapse"                function=                "tabpanel"                aria-labelledby=                "headingThree"                >                <div                class=                "panel-torso"                >                Anim pariatur platitude reprehenderit, enim eiusmod loftier life accusamus terry richardson ad squid. iii wolf moon officia aute, non cupidatat skateboard dolor brunch. Nutrient truck quinoa nesciunt laborum eiusmod. Brunch iii wolf moon tempor, sunt aliqua put a bird on information technology squid unmarried-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, arts and crafts beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer subcontract-to-tabular array, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.                </div>                </div>                </div>                </div>                          

Information technology's also possible to swap out .panel-trunksouth with .list-groupings.

Collapsible list group

  • Bootply
  • Ane itmus air-conditioning facilin
  • 2nd eros

Make expand/collapse controls accessible

Be certain to add aria-expanded to the command chemical element. This attribute explicitly defines the current state of the collapsible element to screen readers and similar assistive technologies. If the collapsible chemical element is closed past default, information technology should take a value of aria-expanded="false". If you lot've set the collapsible chemical element to exist open by default using the in class, set aria-expanded="true" on the control instead. The plugin volition automatically toggle this attribute based on whether or non the collapsible chemical element has been opened or closed.

Additionally, if your control chemical element is targeting a single collapsible element – i.e. the data-target attribute is pointing to an id selector – you may add an boosted aria-controls attribute to the control element, containing the id of the collapsible element. Modern screen readers and like assistive technologies make use of this attribute to provide users with boosted shortcuts to navigate directly to the collapsible element itself.

Usage

The collapse plugin utilizes a few classes to handle the heavy lifting:

  • .collapse hides the content
  • .plummet.in shows the content
  • .collapsing is added when the transition starts, and removed when information technology finishes

These classes tin be found in component-animations.less.

Via data attributes

Simply add together data-toggle="collapse" and a data-target to the element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Exist sure to add together the class collapse to the collapsible element. If you'd like it to default open, add the additional course in.

To add accordion-like grouping management to a collapsible control, add the data attribute data-parent="#selector". Refer to the demo to run across this in activeness.

Via JavaScript

Enable manually with:

                              $                (                '.collapse'                ).                collapse                ()                          

Options

Options can be passed via information attributes or JavaScript. For data attributes, append the pick name to data-, equally in information-parent="".

Name type default clarification
parent selector imitation If a selector is provided, so all collapsible elements under the specified parent will be closed when this collapsible item is shown. (like to traditional accordion behavior - this is dependent on the console class)
toggle boolean truthful Toggles the collapsible element on invocation

Methods

.collapse(options)

Activates your content as a collapsible element. Accepts an optional options object.

                              $                (                '#myCollapsible'                ).                collapse                ({                toggle                :                false                })                          

.collapse('toggle')

Toggles a collapsible element to shown or hidden. Returns to the caller earlier the collapsible element has really been shown or hidden (i.east. before the shown.bs.plummet or hidden.bs.plummet issue occurs).

.collapse('evidence')

Shows a collapsible chemical element. Returns to the caller before the collapsible element has actually been shown (i.east. before the shown.bs.collapse event occurs).

.collapse('hide')

Hides a collapsible element. Returns to the caller before the collapsible element has actually been hidden (i.due east. before the hidden.bs.collapse event occurs).

Events

Bootstrap's plummet class exposes a few events for hooking into collapse functionality.

Event Blazon Description
show.bs.collapse This outcome fires immediately when the show example method is called.
shown.bs.collapse This consequence is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).
hide.bs.collapse This issue is fired immediately when the hide method has been chosen.
hidden.bs.collapse This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to consummate).
                              $                (                '#myCollapsible'                ).                on                (                'hidden.bs.plummet'                ,                function                ()                {                // do something…                })                          

A slideshow component for cycling through elements, like a carousel. Nested carousels are non supported.

                              <div                id=                "carousel-example-generic"                class=                "carousel slide"                information-ride=                "carousel"                >                <!-- Indicators -->                <ol                course=                "carousel-indicators"                >                <li                data-target=                "#carousel-example-generic"                data-slide-to=                "0"                class=                "active"                ></li>                <li                data-target=                "#carousel-example-generic"                data-slide-to=                "one"                ></li>                <li                data-target=                "#carousel-example-generic"                data-slide-to=                "ii"                ></li>                </ol>                <!-- Wrapper for slides -->                <div                class=                "carousel-inner"                role=                "listbox"                >                <div                grade=                "item agile"                >                <img                src=                "..."                alt=                "..."                >                <div                class=                "carousel-caption"                >                ...                </div>                </div>                <div                class=                "item"                >                <img                src=                "..."                alt=                "..."                >                <div                class=                "carousel-caption"                >                ...                </div>                </div>                ...                </div>                <!-- Controls -->                <a                course=                "left carousel-control"                href=                "#carousel-example-generic"                role=                "button"                data-slide=                "prev"                >                <span                form=                "glyphicon glyphicon-chevron-left"                aria-hidden=                "true"                ></bridge>                <span                grade=                "sr-just"                >Previous</span>                </a>                <a                class=                "correct carousel-command"                href=                "#carousel-instance-generic"                part=                "push"                data-slide=                "next"                >                <span                class=                "glyphicon glyphicon-chevron-right"                aria-hidden=                "true"                ></span>                <span                class=                "sr-only"                >Next</span>                </a>                </div>                          

Optional captions

Add together captions to your slides hands with the .carousel-caption element within any .item. Identify just nearly whatsoever optional HTML within there and it volition exist automatically aligned and formatted.

                              <div                form=                "item"                >                <img                src=                "..."                alt=                "..."                >                <div                class=                "carousel-explanation"                >                <h3>...</h3>                <p>...</p>                </div>                </div>                          

Multiple carousels

Carousels require the use of an id on the outermost container (the .carousel) for carousel controls to function properly. When adding multiple carousels, or when changing a carousel's id, exist sure to update the relevant controls.

Via data attributes

Utilize data attributes to easily control the position of the carousel. information-slide accepts the keywords prev or next, which alters the slide position relative to its current position. Alternatively, employ data-slide-to to pass a raw slide index to the carousel data-slide-to="two", which shifts the slide position to a particular index showtime with 0.

The information-ride="carousel" aspect is used to marking a carousel every bit animative starting at page load. It cannot be used in combination with (redundant and unnecessary) explicit JavaScript initialization of the aforementioned carousel.

Via JavaScript

Telephone call carousel manually with:

                              $                (                '.carousel'                ).                carousel                ()                          

Options tin can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-interval="".

Proper noun type default description
interval number 5000 The amount of time to delay between automatically cycling an item. If false, carousel will non automatically cycle.
pause string | zero "hover" If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If set to nix, hovering over the carousel won't pause it.
wrap boolean true Whether the carousel should bike continuously or have hard stops.
keyboard boolean true Whether the carousel should react to keyboard events.

.carousel(options)

Initializes the carousel with an optional options object and starts cycling through items.

                              $                (                '.carousel'                ).                carousel                ({                interval                :                2000                })                          

.carousel('bike')

Cycles through the carousel items from left to right.

.carousel('intermission')

Stops the carousel from cycling through items.

.carousel(number)

Cycles the carousel to a item frame (0 based, similar to an array).

.carousel('prev')

Cycles to the previous item.

.carousel('next')

Cycles to the adjacent item.

Bootstrap's carousel grade exposes 2 events for hooking into carousel functionality.

Both events have the post-obit additional backdrop:

  • management: The direction in which the carousel is sliding (either "left" or "right").
  • relatedTarget: The DOM element that is being slid into place as the active item.

All carousel events are fired at the carousel itself (i.e. at the <div grade="carousel">).

Effect Blazon Description
slide.bs.carousel This event fires immediately when the slide instance method is invoked.
slid.bs.carousel This event is fired when the carousel has completed its slide transition.
                              $                (                '#myCarousel'                ).                on                (                'slide.bs.carousel'                ,                function                ()                {                // exercise something…                })                          

Example

The affix plugin toggles position: fixed; on and off, emulating the consequence establish with position: pasty;. The subnavigation on the right is a alive demo of the affix plugin.


Usage

Utilise the affix plugin via data attributes or manually with your own JavaScript. In both situations, yous must provide CSS for the positioning and width of your affixed content.

Annotation: Do not employ the braze plugin on an chemical element contained in a relatively positioned element, such as a pulled or pushed column, due to a Safari rendering problems.

Positioning via CSS

The affix plugin toggles between three classes, each representing a particular land: .affix, .affix-elevation, and .braze-bottom. Y'all must provide the styles, with the exception of position: fixed; on .affix, for these classes yourself (independent of this plugin) to handle the bodily positions.

Here'south how the affix plugin works:

  1. To start, the plugin adds .affix-top to signal the chemical element is in its acme-almost position. At this point no CSS positioning is required.
  2. Scrolling by the element you desire affixed should trigger the actual affixing. This is where .affix replaces .affix-elevation and sets position: stock-still; (provided past Bootstrap's CSS).
  3. If a bottom offset is defined, scrolling past it should replace .braze with .braze-bottom. Since offsets are optional, setting one requires you to set the appropriate CSS. In this instance, add position: absolute; when necessary. The plugin uses the data attribute or JavaScript option to make up one's mind where to position the chemical element from there.

Follow the to a higher place steps to set your CSS for either of the usage options below.

Via data attributes

To hands add affix behavior to whatever chemical element, merely add information-spy="affix" to the element you lot want to spy on. Use offsets to define when to toggle the pinning of an element.

                              <div                data-spy=                "braze"                data-starting time-meridian=                "sixty"                data-offset-lesser=                "200"                >                ...                </div>                          

Via JavaScript

Call the affix plugin via JavaScript:

                              $                (                '#myAffix'                ).                affix                ({                beginning                :                {                top                :                100                ,                bottom                :                role                ()                {                return                (                this                .                lesser                =                $                (                '.footer'                ).                outerHeight                (                true                ))                }                }                })                          

Options

Options tin can be passed via data attributes or JavaScript. For data attributes, suspend the selection name to data-, as in information-first-elevation="200".

Name blazon default clarification
offset number | function | object 10 Pixels to commencement from screen when calculating position of scroll. If a single number is provided, the showtime volition be applied in both top and bottom directions. To provide a unique, lesser and acme showtime just provide an object offset: { peak: ten } or offset: { top: x, bottom: 5 }. Use a function when you need to dynamically summate an outset.
target selector | node | jQuery element the window object Specifies the target chemical element of the braze.

Methods

.affix(options)

Activates your content as affixed content. Accepts an optional options object.

                              $                (                '#myAffix'                ).                affix                ({                offset                :                15                })                          

.affix('checkPosition')

Recalculates the state of the braze based on the dimensions, position, and scroll position of the relevant elements. The .braze, .affix-pinnacle, and .affix-lesser classes are added to or removed from the affixed content according to the new land. This method needs to be called whenever the dimensions of the affixed content or the target element are changed, to ensure correct positioning of the affixed content.

                              $                (                '#myAffix'                ).                affix                (                'checkPosition'                )                          

Events

Bootstrap's braze plugin exposes a few events for hooking into affix functionality.

Effect Blazon Description
affix.bs.affix This event fires immediately before the element has been affixed.
affixed.bs.affix This event is fired after the element has been affixed.
affix-summit.bs.affix This event fires immediately before the element has been affixed-top.
affixed-top.bs.affix This upshot is fired after the chemical element has been affixed-top.
affix-bottom.bs.braze This outcome fires immediately earlier the chemical element has been affixed-bottom.
affixed-bottom.bs.braze This event is fired subsequently the element has been affixed-bottom.