Chapter 4. Using Bootstrap JavaScript Components

Bootstrap's JavaScript features are all built on top of the jQuery library and either provide completely new functionality or extend the functionality of the existing Bootstrap components.

The plugins can be used by simply adding data attributes to your page elements, but they can also provide a rich programmatic API, if needed.

In this chapter, we will cover the following topics:

  • Using dropdown menus and creating a cascading dropdown menu
  • How to use modal dialogs
  • Separate content inside views with tabs
  • How to implement tooltips and popovers
  • How to use the accordion component
  • Creating a slideshow using the carousel

Data attributes versus the programmatic API

Bootstrap offers the ability to use its plugins entirely through HTML markup. This means that in order to use most of the plugins, you do not need to write a single line of JavaScript. Using data attributes is the recommended approach and should be your first option when using Bootstrap plugins.

For example, to allow an alert element to be dismissible, you'll add the data-dismiss="alert" attribute to either a button or anchor element, as illustrated in the following code:

<div class="alert alert-danger"> 
    <button data-dismiss="alert" class="close" type="button">×</button> 
    <strong>Warning</strong> Shuttle launch in t-minus 10 seconds. 
</div> 

You also have the option to perform the same action using the programmatic API via JavaScript. The following code uses jQuery to close a specific alert element when the user clicks on a button:

<button class="close" type="button" onclick="$('#myalert').alert('close')">×</button> 

Tip

In order to use Bootstrap plugins, you'll need to include the bootstrap.js or bootstrap.min.js file in your project. This file contains all the Bootstrap plugins, but if you do not intend to use every plugin in your project you can choose to download a custom build. At the time of writing, these include Reboot, Grid only, and Flexbox builds.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.34.39