I am encountering an issue with my bootstrap dropdown. I am trying to loop a specific number of times and append each loop number inside a li
. However, my current code is not working as expected. Can anyone provide guidance on how to fix this? Thank you in advance.
for (var i = 0; i < 5; i++) {
console.log(i)
$('.dropdown-menu ul').append(`<li><a class="dropdown-item">test ${i}</a></li>`)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
<div class="dropdown">
<button class="btn btn-secondary w-100 d-flex justify-content-between align-items-center" type="button" data-bs-toggle="dropdown">test</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
</ul>
</div>