Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap drop down menu doesn't open

I am having trouble getting my dropdown's to work. I can get the navbar to show up perfectly, but when I click on "Dropdown" (either of them) it does not display the dropdown menu. I have tried looking on other posts about this, but nothing that fixed everyone's problems helped. Here is the code

<head>
    <meta charset="UTF-8">
    <title>Landing Page</title>
    <meta http-equiv="X-UA-COMPATIBLE" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <script type="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
    <script type="javascript" src="dist/js/bootstrap.js"></script>
    <script type="javascript">
        $(document).ready(function() {
            $(".dropdown-toggle").dropdown();
        });

    </script>
    <link href="dist/css/bootstrap.css" rel="stylesheet">
    <link href="styles.css" rel="stylesheet">

</head>
<body>
<div class="navbar-wrapper"><!-- navbar start -->
    <div class="container">
        <nav class="navbar navbar-inverse navbar-static-top">
            <div class="container">
                <div class="navbar-header">
                   <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                           data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                       <span class="sr-only">Toggle navigation</span>
                       <span class="icon-bar"></span>
                       <span class="icon-bar"></span>
                       <span class="icon-bar"></span>
                   </button>
                    <a class="navbar-brand" href="#">Project name</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">Home</a> </li>
                        <li><a href="#about">About</a> </li>
                        <li><a href="#about">Contact</a> </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Dropdown <span class="caret"></span></a>
                            <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 role="separator" class="divider"></li>
                                <li class="dropdown-header">Nav header</li>
                                <li><a href="#">Separated link</a></li>
                                <li><a href="#">One more separated link</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
</div><!-- navbar end -->
<!-- Placed at the end of the document so the pages load faster -->

</body>
like image 501
Brk Avatar asked Feb 06 '16 10:02

Brk


2 Answers

In my case, I loaded bootstrap JS twice. Removed duplicate one and it worked.

like image 141
mansoor.khan Avatar answered Oct 16 '22 18:10

mansoor.khan


The problem is in your stylesheet or bootstrap js Link (look at below). Check again!

<script type="javascript" src="dist/js/bootstrap.js"></script>
<link href="dist/css/bootstrap.css" rel="stylesheet">
like image 32
Joe Kdw Avatar answered Oct 16 '22 16:10

Joe Kdw