Home > front end >  Bootstrap 5 Dropdown menu does not work, unsure of what is going on
Bootstrap 5 Dropdown menu does not work, unsure of what is going on

Time:11-30

my entire code is below, I do not have a main.js file yet. Just trying to get the dropdown menu to work but regardless of what I press the dropdown menu will not drop.

Here is my 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.0">
  <title>Bootstrap</title>
  <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
  
</head>
<body>
  <li >
    <a  href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      Dropdown
    </a>
    <div  aria-labelledby="navbarDropdown">
      <a  href="#">Action</a>
      <a  href="#">Another action</a>
      <div ></div>
      <a  href="#">Something else here</a>
    </div>
  </li>
  <script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>
</body>
</html>

Thanks!

CodePudding user response:

You Should Import Bootstrap using CDNs and data-bs-toggle="dropdown" should be present in Button which opens dropdown

<!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.0">
  <title>Bootstrap</title>
 <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
  
</head>
<body>
  <li >
    <a  href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      Dropdown
    </a>
    <div  aria-labelledby="navbarDropdown">
      <a  href="#">Action</a>
      <a  href="#">Another action</a>
      <div ></div>
      <a  href="#">Something else here</a>
    </div>
  </li>
 <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script></script>
</body>
</html>

CodePudding user response:

I guess you need to link ##bootstrap. min. js## file in your script src.

  • Related