Bootstrap Question:

Explain me how do you use the Dropdown plugin?

Tweet Share WhatsApp

Answer:

You can toggle the dropdown plugin's hidden content −

☛ Via data attributes − Add data-toggle = "dropdown" to a link or button to toggle a dropdown as shown below −

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

☛ If you need to keep links intact (which is useful if the browser is not enabling JavaScript), 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 − To call the dropdown toggle via JavaScript, use the following method −

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

Download Bootstrap PDF Read All 128 Bootstrap Questions
Previous QuestionNext Question
Do you know what are input groups?Explain me how many different media queries are used by the Bootstrap grid system by default?