I download bootstrap and linked the css and js bundle files yet bootstrap components are not loading properly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
<script src="js/bootstrap.bundle.js"></script>
</body>
</html>
js is not working in dropdownenter image description here menus etc. the components look weird too. Is there something wrong I am doing?
2
Answers
You have not included your bootstap version. If you are using Bootstrap 5, add
data-bs-toggle="dropdown"
to you button element – that might be a reason why it does not work –> see here: https://getbootstrap.com/docs/5.0/components/dropdowns/In Bootstrap 5 components like dropdowns rely on data attributes or JavaScript for initialization. For dropdowns the proper data attribute is
data-bs-toggle="dropdown"
.