Bootstrap JS Dropdown

Dropdown CSS Classes

For a tutorial about Dropdowns, read our Bootstrap Dropdowns Tutorial.
ClassDescriptionExample
.dropdownIndicates a dropdown menuTry it
.dropdown-itemStyle links inside the dropdown menu with proper padding etcTry it
.dropdown-item-textStyle text or text links inside the dropdown menu with proper padding etcTry it
.dropdown-menuBuilds the dropdown menuTry it
.dropdown-menu-rightRight-aligns a dropdown menuTry it
.dropdown-headerAdds a header inside the dropdown menuTry it
.dropupIndicates a dropup menuTry it
.disabledDisables an item in the dropdown menuTry it
.activeStyles the active element in a dropdown menuTry it
.dividerSeparates items inside the dropdown menu with a horizontal lineTry it

Via data-* Attributes

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

Example

<button type="button" class="dropdown-toggle" data-toggle="dropdown">Dropdown Example</button>
Try it Yourself »

Via JavaScript

Enable manually with:

Example

$('.dropdown-toggle').dropdown();
Try it Yourself »
Note: The data-toggle="dropdown" attribute is required regardless of whether you call the dropdown() method.

Dropdown Options

None

Dropdown Methods

The following table lists all available dropdown methods.
MethodDescriptionTry it
.dropdown("toggle")Toggles the dropdown. If set, it will open the dropdown menu by defaultTry it
.dropdown("update")Updates the position of an element's dropdown
.dropdown("dispose")Destroys an element's dropdown

Dropdown Events

The following table lists all available dropdown events.
EventDescriptionTry it
show.bs.dropdownOccurs when the dropdown is about to be shown.Try it
shown.bs.dropdownOccurs when the dropdown is fully shown (after CSS transitions have completed)Try it
hide.bs.dropdownOccurs when the dropdown is about to be hiddenTry it
hidden.bs.dropdownOccurs when the dropdown is fully hidden (after CSS transitions have completed)Try it
Tip: Use jQuery's event.relatedTarget to get the element which triggered the dropdown:

Example

$(".dropdown").on("show.bs.dropdown"function(event){
  var x = $(event.relatedTarget).text(); // Get the text of the element  alert(x);
});
Try it Yourself »



Credit: www.w3schools.com
Bootstrap JS Dropdown Bootstrap JS Dropdown Reviewed by webmission on 11:15 Rating: 5

No comments:

Powered by Blogger.