<metaname="twitter:description"content="Bring Bootstrap to life with our optional JavaScript plugins built on jQuery. Learn about each plugin, our data and programmatic API options, and more.">
<metaproperty="og:description"content="Bring Bootstrap to life with our optional JavaScript plugins built on jQuery. Learn about each plugin, our data and programmatic API options, and more.">
<pclass="bd-lead">Bring Bootstrap to life with our optional JavaScript plugins built on jQuery. Learn about each plugin, our data and programmatic API options, and more.</p>
<h2id="individual-or-compiled">Individual or compiled</h2>
<p>Plugins can be included individually (using Bootstrap’s individual <codeclass="highlighter-rouge">*.js</code> files), or all at once using <codeclass="highlighter-rouge">bootstrap.js</code> or the minified <codeclass="highlighter-rouge">bootstrap.min.js</code> (don’t include both).</p>
<h2id="dependencies">Dependencies</h2>
<p>Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs. Also note that <strong>all plugins depend on jQuery</strong> (this means jQuery must be included <strong>before</strong> the plugin files). <ahref="https://github.com/twbs/bootstrap/blob/v4.0.0-beta/bower.json">Consult our <codeclass="highlighter-rouge">bower.json</code></a> to see which versions of jQuery are supported.</p>
<p>Our tooltips and popovers also depend on <ahref="https://github.com/FezVrasta/popper.js">Popper.js</a>.</p>
<h2id="data-attributes">Data attributes</h2>
<p>Nearly all Bootstrap plugins can be enabled and configured through HTML alone with data attributes (our preferred way of using JavaScript functionality). Be sure to <strong>only use one set of data attributes on a single element</strong> (e.g., you cannot trigger a tooltip and modal from the same button.)</p>
<p>However, in some situations it may be desirable to disable this functionality. To disable the data attribute API, unbind all events on the document namespaced with <codeclass="highlighter-rouge">data-api</code> like so:</p>
<p>Bootstrap provides custom events for most plugins’ unique actions. Generally, these come in an infinitive and past participle form - where the infinitive (ex. <codeclass="highlighter-rouge">show</code>) is triggered at the start of an event, and its past participle form (ex. <codeclass="highlighter-rouge">shown</code>) is triggered on the completion of an action.</p>
<p>All infinitive events provide <ahref="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault"><codeclass="highlighter-rouge">preventDefault()</code></a> functionality. This provides the ability to stop the execution of an action before it starts.</p>
<spanclass="k">if</span><spanclass="p">(</span><spanclass="o">!</span><spanclass="nx">data</span><spanclass="p">)</span><spanclass="k">return</span><spanclass="nx">e</span><spanclass="p">.</span><spanclass="nx">preventDefault</span><spanclass="p">()</span><spanclass="c1">// stops modal from being shown</span>
<spanclass="p">})</span></code></pre></figure>
<h2id="programmatic-api">Programmatic API</h2>
<p>We also believe you should be able to use all Bootstrap plugins purely through the JavaScript API. All public APIs are single, chainable methods, and return the collection acted upon.</p>
<p>All methods should accept an optional options object, a string which targets a particular method, or nothing (which initiates a plugin with default behavior):</p>
<figureclass="highlight"><pre><codeclass="language-js"data-lang="js"><spanclass="nx">$</span><spanclass="p">(</span><spanclass="s1">'#myModal'</span><spanclass="p">).</span><spanclass="nx">modal</span><spanclass="p">()</span><spanclass="c1">// initialized with defaults</span>
<spanclass="nx">$</span><spanclass="p">(</span><spanclass="s1">'#myModal'</span><spanclass="p">).</span><spanclass="nx">modal</span><spanclass="p">({</span><spanclass="na">keyboard</span><spanclass="p">:</span><spanclass="kc">false</span><spanclass="p">})</span><spanclass="c1">// initialized with no keyboard</span>
<spanclass="nx">$</span><spanclass="p">(</span><spanclass="s1">'#myModal'</span><spanclass="p">).</span><spanclass="nx">modal</span><spanclass="p">(</span><spanclass="s1">'show'</span><spanclass="p">)</span><spanclass="c1">// initializes and invokes show immediately</span></code></pre></figure>
<p>Each plugin also exposes its raw constructor on a <codeclass="highlighter-rouge">Constructor</code> property: <codeclass="highlighter-rouge">$.fn.popover.Constructor</code>. If you’d like to get a particular plugin instance, retrieve it directly from an element: <codeclass="highlighter-rouge">$('[rel="popover"]').data('popover')</code>.</p>
<h3id="asynchronous-functions-and-transitions">Asynchronous functions and transitions</h3>
<p>All programmatic API methods are <strong>asynchronous</strong> and returns to the caller once the transition is started but <strong>before it ends</strong>.</p>
<p>In order to execute an action once the transition is complete, you can listen to the corresponding event.</p>
<spanclass="nx">$</span><spanclass="p">(</span><spanclass="s1">'#myCarousel'</span><spanclass="p">).</span><spanclass="nx">carousel</span><spanclass="p">(</span><spanclass="s1">'2'</span><spanclass="p">)</span><spanclass="c1">// Will slide to the slide 2 as soon as the transition to slide 1 is finished</span>
<spanclass="p">})</span>
<spanclass="nx">$</span><spanclass="p">(</span><spanclass="s1">'#myCarousel'</span><spanclass="p">).</span><spanclass="nx">carousel</span><spanclass="p">(</span><spanclass="s1">'1'</span><spanclass="p">)</span><spanclass="c1">// Will start sliding to the slide 1 and returns to the caller</span>
<spanclass="nx">$</span><spanclass="p">(</span><spanclass="s1">'#myCarousel'</span><spanclass="p">).</span><spanclass="nx">carousel</span><spanclass="p">(</span><spanclass="s1">'2'</span><spanclass="p">)</span><spanclass="c1">// !! Will be ignored, as the transition to the slide 1 is not finished !!</span></code></pre></figure>
<h3id="default-settings">Default settings</h3>
<p>You can change the default settings for a plugin by modifying the plugin’s <codeclass="highlighter-rouge">Constructor.Default</code> object:</p>
<figureclass="highlight"><pre><codeclass="language-js"data-lang="js"><spanclass="nx">$</span><spanclass="p">.</span><spanclass="nx">fn</span><spanclass="p">.</span><spanclass="nx">modal</span><spanclass="p">.</span><spanclass="nx">Constructor</span><spanclass="p">.</span><spanclass="nx">Default</span><spanclass="p">.</span><spanclass="nx">keyboard</span><spanclass="o">=</span><spanclass="kc">false</span><spanclass="c1">// changes default for the modal plugin's `keyboard` option to false</span></code></pre></figure>
<h2id="no-conflict">No conflict</h2>
<p>Sometimes it is necessary to use Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. If this happens, you may call <codeclass="highlighter-rouge">.noConflict</code> on the plugin you wish to revert the value of.</p>
<figureclass="highlight"><pre><codeclass="language-js"data-lang="js"><spanclass="kd">var</span><spanclass="nx">bootstrapButton</span><spanclass="o">=</span><spanclass="nx">$</span><spanclass="p">.</span><spanclass="nx">fn</span><spanclass="p">.</span><spanclass="nx">button</span><spanclass="p">.</span><spanclass="nx">noConflict</span><spanclass="p">()</span><spanclass="c1">// return $.fn.button to previously assigned value</span>
<spanclass="nx">$</span><spanclass="p">.</span><spanclass="nx">fn</span><spanclass="p">.</span><spanclass="nx">bootstrapBtn</span><spanclass="o">=</span><spanclass="nx">bootstrapButton</span><spanclass="c1">// give $().bootstrapBtn the Bootstrap functionality</span></code></pre></figure>
<h2id="version-numbers">Version numbers</h2>
<p>The version of each of Bootstrap’s jQuery plugins can be accessed via the <codeclass="highlighter-rouge">VERSION</code> property of the plugin’s constructor. For example, for the tooltip plugin:</p>
<h2id="no-special-fallbacks-when-javascript-is-disabled">No special fallbacks when JavaScript is disabled</h2>
<p>Bootstrap’s plugins don’t fall back particularly gracefully when JavaScript is disabled. If you care about the user experience in this case, use <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript"><codeclass="highlighter-rouge"><noscript></code></a> to explain the situation (and how to re-enable JavaScript) to your users, and/or add your own custom fallbacks.</p>
<p><strong>Bootstrap does not officially support third-party JavaScript libraries</strong> like Prototype or jQuery UI. Despite <codeclass="highlighter-rouge">.noConflict</code> and namespaced events, there may be compatibility problems that you need to fix on your own.</p>
</div>
<h2id="util">Util</h2>
<p>All Bootstrap Javascript depend on <codeclass="highlighter-rouge">util.js</code> and it has to be included alongside the other JS files. If you’re using the compiled (or minified) <codeclass="highlighter-rouge">bootstrap.js</code>, there is no need to include this—it’s already there.</p>
<p><codeclass="highlighter-rouge">util.js</code> includes utility functions and a basic helper for <codeclass="highlighter-rouge">transitionEnd</code> events as well as a CSS transition emulator. It’s used by the other plugins to check for CSS transition support and to catch hanging transitions.</p>