I am attempting to display a dropdown using JavaScript, but it appears there is an issue with Bootstrap 5. When trying to show the dropdown, an exception is thrown:
Uncaught TypeError: Cannot read property 'classList' of undefined at _e.show (dropdown.js:140)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="462429293235323427360673687668766b2423322775">[email protected]</a>/dist/css/bootstrap.min.css">
</head>
<body>
<div id="testDropdown" class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
<div id="testModal" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c6cbcbd0d7d0d6c5d4e4918a948a9489c6c1d0c597">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<script>
let testModal = document.getElementById("testModal");
//new bootstrap.Modal(testModal).show(); //works
let testDropdown = document.getElementById("testDropdown");
new bootstrap.Dropdown(testDropdown).show(); //does not work
</script>
</body>
</html>
Is there a mistake on my end or is this a bug?
Thank you in advance.