JavaScript Components

Examples

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.

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's 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 whatever keytar, scenester farm-to-table banksy Austin twitter handle freegan cred raw denim single-origin coffee viral.

Four directions


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

Opt-in functionality

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

Tooltips in button groups and input groups require special setting

When using tooltips on elements within a .btn-group or an .input-group, you'll have to specify the option container: 'body' (documented below) to avoid unwanted side effects (such as the element growing wider and/or losing its rounded corners when the tooltip is triggered).

Tooltips on disabled elements require wrapper elements

To add a tooltip to a disabled or .disabled element, put the element inside of a <div> and apply the tooltip to that <div> instead.

Usage

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

Trigger the tooltip via JavaScript:


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

Markup

The required markup for a tooltip is only a data attribute and title on the HTML element you 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 by the plugin).

Multiple-line links

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


   1 <!-- HTML to write -->
   2 <a href="#" data-toggle="tooltip" title="Some tooltip text!">Hover over me</a>
   3
   4 <!-- Generated markup by the plugin -->
   5 <div class="tooltip top">
   6   <div class="tooltip-inner">
   7     Some tooltip text!
   8   </div>
   9   <div class="tooltip-arrow"></div>
  10 </div>

Options

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

Name type default description
animation boolean true apply a CSS fade transition to the tooltip
html boolean false Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.
placement string | function 'top' how to position the tooltip - top | bottom | left | right | auto.
When "auto" 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 right.
selector string false If a selector is provided, tooltip objects will be delegated to the specified targets.
title string | function '' default title value if title attribute isn't present
trigger string 'hover focus' how tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.
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 structure is: delay: { show: 500, hide: 100 }

container string | false false

Appends the tooltip to a specific element. Example: container: 'body'

Data attributes for individual tooltips

Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.

Methods

$().tooltip(options)

Attaches a tooltip handler to an element collection.

.tooltip('show')

Reveals an element's tooltip.


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

.tooltip('hide')

Hides an element's tooltip.


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

.tooltip('toggle')

Toggles an element's tooltip.


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

.tooltip('destroy')

Hides and destroys an element's tooltip.


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

Events

Event Type Description
show.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 event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete).

$('#myTooltip').on('hidden.bs.tooltip', function () {
  // do something¦
})

Examples

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

Within a navbar

Within pills

Via data attributes or JavaScript, the dropdown plugin toggles hidden content (dropdown menus) by toggling the .open class on the parent list item. When opened, the plugin also adds .dropdown-backdrop as a click area for closing dropdown menus when clicking outside the menu. Note: The data-toggle=dropdown attribute is relied on for closing dropdown menus at an application level, so it's a good idea to always use it.

Via data attributes

Add data-toggle="dropdown" to a link or button to toggle a dropdown.


<div class="dropdown">
  <a data-toggle="dropdown" href="#">Dropdown trigger</a>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
    ...
  </ul>
</div>

To keep URLs intact, use the data-target attribute instead of href="#".


<div class="dropdown">
  <a id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="/page.html">
    Dropdown
    <span class="caret"></span>
  </a>

  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
    ...
  </ul>
</div>

Via JavaScript

Call the dropdowns via JavaScript:

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

data-toggle="dropdown" still required

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

Options

None

Methods

$().dropdown('toggle')

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

Events

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

Event Type Description
show.bs.dropdown This event fires immediately when the show instance method is called. The toggling anchor element is available as the relatedTarget property of the event.
shown.bs.dropdown This event is fired when the dropdown has been made visible to the user (will wait for CSS transitions, to complete). The toggling anchor element is available as the relatedTarget property of the event.
hide.bs.dropdown This event is fired immediately when the hide instance method has been called. The toggling anchor element is available as the relatedTarget property of the event.
hidden.bs.dropdown This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete). The toggling anchor element is available as the relatedTarget property of the event.

$('#myDropdown').on('show.bs.dropdown', function () {
  // do something¦
})

The Drawer Template lets you organize content into "drawers" or expandable / collapsible subsections in the center of the page. Each drawer consists of a Drawer Title, where you enter a given section's title text and a Drawer Body where you input its corresponding content. This template is ideal for lengthy content (such as FAQs).

Drawer Heading 1

Nulla nec lectus at orci tempor blandit. Sed nisi ipsum, iaculis nec pharetra non, mollis sit amet arcu. Aliquam erat volutpat. Cras laoreet semper est vitae vestibulum. Aenean eleifend ipsum ut purus sodales pellentesque. Cras commodo, enim eu aliquam aliquam, diam urna tincidunt nibh, quis suscipit ante neque sit amet ligula. Curabitur aliquam, eros in egestas vehicula, ipsum neque hendrerit felis, dapibus vulputate sem nunc non nunc. Morbi sit amet neque eu libero tristique bibendum. Maecenas feugiat venenatis elit, sed luctus sapien molestie id. Duis at nulla odio. Quisque a urna sit amet tellus auctor dignissim nec id mauris. Proin semper enim in eros iaculis dictum.

Drawer Heading 2

Suspendisse sit amet lectus est, sed ornare neque. Cras dignissim odio sit amet mi tempor vel consectetur dui elementum. Donec mi libero, luctus a ultricies at, ullamcorper quis lacus. Pellentesque ut purus ut erat semper pulvinar. In hac habitasse platea dictumst. Sed at vehicula sem. Donec eu elit erat, eleifend mollis mauris. Sed faucibus mollis bibendum. Suspendisse potenti. Donec sed lorem velit, consequat fermentum ligula. Duis commodo pellentesque vulputate.

Drawer Heading 3

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vestibulum vehicula tortor ac elementum. Phasellus non ligula sem, sed rhoncus ipsum. Suspendisse eget lacus eget nibh faucibus dictum in in elit. Quisque tellus dui, ultrices eget dictum nec, pulvinar eu quam. Nulla ut dolor dolor. Nam viverra lacinia neque, quis porttitor metus porttitor nec. Suspendisse tempor rhoncus magna, sed egestas lacus fringilla id. Nam posuere vestibulum scelerisque. Praesent semper, leo vitae aliquet viverra, leo ante egestas leo, eu auctor magna est ut dui. Praesent eget tristique lacus. Etiam mollis dolor iaculis elit sollicitudin feugiat in ut est. Morbi ultricies bibendum interdum.

<div class="drawer">
  <h2><a href="#">Drawer Heading 1</a></h2>
  <div>
    Nulla nec lectus at orci tempor blandit. Sed nisi ipsum, iaculis nec pharetra non, mollis sit amet
  </div>

  <h2><a href="#">Drawer Heading 2</a></h2>
  <div>
    Suspendisse sit amet lectus est, sed ornare neque. Cras dignissim odio sit amet mi tempor vel
  </div>

  <h2><a href="#">Drawer Heading 3</a></h2>
  <div>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vestibulum vehicula tortor ac
  </div>
</div>

<div class="flexslider">
  <ul class="slides">
    <!--Image and caption-->
    <li>
      <img alt="Sophia Suarez researches nanomedicine" src="_images/rt_img/rt_2.jpg"/>
      <p class="flex-caption">Students make some noise during Spirit Night.</p>
    </li>

    <!--Image, caption and link-->
    <li>
      <img alt="Students make some noise during Spirit Night" src="_images/rt_img/rt_3.jpg"/>
      <p class="flex-caption">
        <a href="http://www.ucsd.edu">Students go surfing at La Jolla Shores</a>
      </p>
    </li>

    <!--Image only-->
    <li>
      <img alt="UC San Diego students on round up carnival ride" src="_images/rt_img/rt_4.jpg"/>
    </li>
  </ul>

  <!--Remove this line to disable rotator controls-->
  <div class="flex-controls"></div>

</div>