Problem Dropdown menu bootstrap

Asked

Viewed 841 times

5

I have my dropdown menu

But I always have to give 2 clicks for him to open the menu, I would like on the first click it already opens...

You could have had him without the element <a?

that’s my code:

 <div class="navbar navbar-default">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>

            <div class="collapse navbar-collapse js-navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Cadastro <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#/clientes">Cliente</a></li>
                        </ul>
                    </li>
        </ul>

            </div><!-- /.nav-collapse -->
        </div>
    </div>
  • Which Javascripts were included with this HTML?

  • jquery followed by bootstrap.js ah, also use Angularjs...until I thought that was it, that every time I click it tries to go up the link #, so I asked if it would have how not to put the element a

1 answer

4


There are two ways:

1. Preventing the standard behaviour of dropdown-toggle

Add the following to your code:

$('.dropdown-toggle').click(function(e) {
    e.preventDefault();
    e.stopPropagation();

    return false;
});

2. Using another class

Change dropdown-toggle for dropdown-menu.

  • 1

    I only used dropdown menu and it worked =D

  • 1

    works with dropdown-submenu also, vlw very @Ciganomorrisonmendez

Browser other questions tagged

You are not signed in. Login or sign up in order to post.