33

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?

1
  • 1
    If you could post some corresponding code. Commented Mar 29, 2013 at 5:45

3 Answers 3

53

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="#">
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks very much for pointing this, i change to use <button> and it works, i think this may be a bug of Bootstrap's doc.
Be careful this only makes the button LOOK disabled (regardless of using A or BUTTON tags), the JS functionality remains enabled on many browsers including IE11 and Chrome, see BS3 Docs
I would add: in case you are using some other inner element like an icon, remember to disable both of them otherwise the dropdown menu will still show up.
16

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');

Comments

9

All you need to do is set the disabled property of the button.

$('.dropdown-toggle').prop('disabled', true);

http://getbootstrap.com/2.3.2/base-css.html#buttons Disabled state

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.