Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitterbootstrap dropdown, open modal

Trying to get a dropdown button to open, and then when clicking on an item in the dropdown it should open a modal - but not working, added this code:

<button type="button" class="btn btn-lg btn-warning dropdown-toggle" data-toggle="dropdown">By industries <span class="caret"></span>
                  </button> 
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="#consumergoods">Consumer goods</a></li>

                    <div class="modal fade" id="consumergoods" data-target="#consumergoods">
                                          <div class="modal-dialog">
                                            <div class="modal-content">
                                              <div class="modal-header orange">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title"><strong></strong>Consumer goods</h4>
                                              </div>

Probably doing something seriously wrong, but I'd be glad if someone could help, thanks!

like image 427
Bernie Avatar asked Feb 10 '23 20:02

Bernie


1 Answers

You need to have a wrapper div .dropdown for the button and <ul> for the dropdown to work and for the modal you need to give the attribute data-toggle="modal" to the link

<div class="dropdown">
    <button type="button" class="btn btn-lg btn-warning dropdown-toggle" data-toggle="dropdown">By industries <span class="caret"></span>    
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#consumergoods" data-toggle="modal">Consumer goods</a></li>
    </ul>
</div>
<div class="modal fade" id="consumergoods" data-target="#consumergoods">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header orange">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>    
                </button>
                 <h4 class="modal-title"><strong></strong>Consumer goods</h4>    
            </div>
        </div>
    </div>
</div>

Fiddle

like image 105
anpsmn Avatar answered Feb 14 '23 01:02

anpsmn