Home > Blockchain >  Bootstrap dropdown not opening when clicking button
Bootstrap dropdown not opening when clicking button

Time:12-21

I am trying to create a dropdown using Bootstrap with several options but when I click the button nothing comes down to select the option. Not sure what is going on.

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>A Basic HTML5 Template</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" >
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" ></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2 xf0Uwh9KtT" crossorigin="anonymous"></script>
</head>

<body>
  <div >
              <button  type="button" id="SelectOS" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Select option...</button>
                <div  aria-labelledby="SelectOS">
                  <a  href="#">Linux</a>
                  <a  href="#">Mac</a>
                  <a  href="#">Windows</a>
                </div>
  </div>
</body>
</html>

CodePudding user response:

Use the data-bs-toggle attribute instead of the data-toggle attribute.

<!doctype html>

<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>A Basic HTML5 Template</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2 xf0Uwh9KtT" crossorigin="anonymous"></script>
</head>

<body>
  <div >
    <button  type="button" id="SelectOS" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Select option...</button>
    <div  aria-labelledby="SelectOS">
      <a  href="#">Linux</a>
      <a  href="#">Mac</a>
      <a  href="#">Windows</a>
    </div>
  </div>
</body>

</html>

  • Related