Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Bootstrap's Button dropdown

Link here: bootstrap button dropdowns

I'd like to disable this button dropdown, i added disabled class to <a> but the dropdown can still be opened by clicking the dropdown button. Any ideas?

like image 919
Mike Avatar asked Mar 29 '13 05:03

Mike


People also ask

How do I disable drop down?

We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute.

How do I toggle a dropdown in Bootstrap?

To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. The . caret class creates a caret arrow icon (), which indicates that the button is a dropdown.

How do I stop dropdown menu Close menu items on clicking inside?

As all Twitter Bootstrap users know, the dropdown menu closes on click (even clicking inside it). To avoid this, I can easily attach a click event handler on the dropdown menu and simply add the famous event. stopPropagation() .

How do I make a dropdown readonly?

Dropdown (select element) is always read only. User do not edit it. User can select any of the option of its own chice. Unlike other html elements, it dont have a attribute which can make the element readony and prevent users to change its value.


2 Answers

Add disabled class to the button...

<div class="btn-group">     <button class="btn btn-primary dropdown-toggle disabled" data-toggle="dropdown">Action <span class="caret"></span></button>     <ul class="dropdown-menu">       <li><a href="#">Action</a></li>       <li><a href="#">Another action</a></li>       <li><a href="#">Something else here</a></li>       <li class="divider"></li>       <li><a href="#">Separated link</a></li>     </ul> </div> 

That works when editing via bootstraps site. I did notice that they're not using the anchor like their example.

<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> 
like image 95
Christopher Marshall Avatar answered Oct 04 '22 18:10

Christopher Marshall


Yeah you can do it this way:

$('.dropdown-toggle').data('toggle', ''); 

This works only when it gets this property: data-toggle="dropdown", You can either change the dropdown to '' blank one.

Or you can try and remove the attr of data-toggle

$('.dropdown-toggle').removeAttr('data-toggle'); 
like image 39
Jai Avatar answered Oct 04 '22 19:10

Jai