Home > Back-end >  Bootstrap collapsable Navbar isn't displaying the menu i.e the dropdown menu for mobile devices
Bootstrap collapsable Navbar isn't displaying the menu i.e the dropdown menu for mobile devices

Time:04-24

I tried creating a collapsable navbar for mobile devices, Although I used Bootstrap 3.3.6 an older version, because I am working on something. The Button shows up, but when I click on it nothing happens, it doesn't display the drop-down menu. I even copy pasted some code from Bootstrap components of 3.3.6 version, in the bootstrap site it works, but when I try the same in my html code it simply doesn't work. not sure what is actually happening here this is the code :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>A Site</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/styles.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Square Peg&display=swap" rel="stylesheet">
</head>
<body>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

    <header>
        <nav >
            <div >
              <!-- Brand and toggle get grouped for better mobile display -->
              <div >
                <button type="button"  data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                  <span >Toggle navigation</span>
                  <span ></span>
                  <span ></span>
                  <span ></span>
                </button>
                <a  href="#">Brand</a>
              </div>
          
              <!-- Collect the nav links, forms, and other content for toggling -->
              <div  id="bs-example-navbar-collapse-1">
                <ul >
                  <li ><a href="#">Link <span >(current)</span></a></li>
                  <li><a href="#">Link</a></li>
                  <li >
                    <a href="#"  data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span ></span></a>
                    <ul >
                      <li><a href="#">Action</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                      <li role="separator" ></li>
                      <li><a href="#">Separated link</a></li>
                      <li role="separator" ></li>
                      <li><a href="#">One more separated link</a></li>
                    </ul>
                  </li>
                </ul>
                <form  role="search">
                  <div >
                    <input type="text"  placeholder="Search">
                  </div>
                  <button type="submit" >Submit</button>
                </form>
                <ul >
                  <li><a href="#">Link</a></li>
                  <li >
                    <a href="#"  data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span ></span></a>
                    <ul >
                      <li><a href="#">Action</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                      <li role="separator" ></li>
                      <li><a href="#">Separated link</a></li>
                    </ul>
                  </li>
                </ul>
              </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
          </nav>
    </header>
</body>

Here's my codepen link: https://codepen.io/MrROBOT_10/pen/gOoyyLe

Here's the Bootstrap components link : https://bootstrapdocs.com/v3.3.6/docs/components/#navbar

CodePudding user response:

In code pen it says jquery not available in the code pen console. So i added

     <script
  src="https://code.jquery.com/jquery-2.2.4.js"
  integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
  crossorigin="anonymous"></script>

just before the final the body tag to get it working

  • Related