jqueryhtmltwitter-bootstrapnavbarjquery-mobile-navbar

Bootstrap navbar won't toggle open when collapsed


I've checked all solutions. I've copied many navbar example codes. My navbar collapses when it is supposed to, but clicking the button won't toggle or expand.

In the head I am referencing the CSS for bootstrap

    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">

On the bottom of the page just before the ending body tag, I am referencing the .js files.

    <script type="text/javascript" src="framework7/js/framework7.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/news-feed.js"></script>
    <script type="text/javascript" src="cordova.js"></script>
    <script defer src="js/fontawesome-all.js"></script>
    <script type="text/javascript" src="js/jquery.3.3.1.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>

And then here is my nav code which I got from bootswatch or bootstrap, don't remember I've tried so many examples.

    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <a class="navbar-brand" href="#">Catholic Cemeteries</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarColor01">
            <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
              <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Features</a>
            </li>
            <li class="nav-item">
               <a class="nav-link" href="#">Pricing</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">About</a>
           </li>
           </ul>

        </div>
      </nav>

Thanks in advance, John


Solution

  • You need popper.js. First jquery.js, then popper.js, then bootstrap.js...

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>
    

    And, make sure there are no JS errors in the browser console.

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/poppe.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>
    
       <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <a class="navbar-brand" href="#">Catholic Cemeteries</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
        </button>
    
        <div class="collapse navbar-collapse" id="navbarColor01">
            <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
              <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Features</a>
            </li>
            <li class="nav-item">
               <a class="nav-link" href="#">Pricing</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">About</a>
           </li>
           </ul>
        </div>
       </nav>