I'm currently working with 3 bootstrap dropdown elements. The toggle for the first two is not controlled by jQuery, but for the third one, I am using jQuery to show and hide it. However, I've encountered some issues that need fixing. When clicking on the buttons for the first two dropdowns, their menus display correctly, while the third dropdown has problems. First of all, its menu doesn't show on the first click; you have to click it a second time to make the menu appear. Secondly, the positioning of the third dropdown menu is incorrect initially, but scrolling on the body fixes this issue. Upon further investigation, I discovered that removing the other two dropdown elements resolves the third dropdown's functionality and corrects the second problem. Despite controlling its toggle with jQuery, I can't seem to figure out what the underlying issue is. How can I go about resolving these issues? Thank you in advance.
$(function() {
$(".account button").click(function() {
$(".account .dropdown-menu").toggle();
});
});
.header {
display: flex;
flex-direction: row;
justify-content: right;
align-items: center;
column-gap: 4%;
width: 100%;
height: 20vh;
background-color: gold;
}
.header .dropdown {
border: none;
}
.header .dropdown button:focus {
box-shadow: none;
}
.header .dropdown.account ul{
transform: translate(0px, 40px) !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css" integrity="sha384-3B6NwesSXE7YJlcLI9RpRqGf2p/EgVH8BgoKTaUrmKNDkHPStTQ3EyoYjCGXaOTS" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b5954544f484f495a4b7b0e150a1508">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e0828f8f949394928190a0d5ced1ced3">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcded3d3c8cfc8ceddccfc89928d928f">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="header">
<div class="dropdown">
<button class="btn btn-secondary" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-solid fa-magnifying-glass"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item switchProfile">option 1</a></li>
<li><a class="dropdown-item myAccount">option 2</a></li>
<li><a class="dropdown-item logOut">option 3</a></li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-secondary" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-solid fa-magnifying-glass"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item switchProfile">option 1</a></li>
<li><a class="dropdown-item myAccount">option 2</a></li>
<li><a class="dropdown-item logOut">option 3</a></li>
</ul>
</div>
<div class="dropdown account">
<button class="btn btn-secondary" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-solid fa-user"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item switchProfile">option 1</a></li>
<li><a class="dropdown-item myAccount">option 2</a></li>
<li><a class="dropdown-item logOut">option 3</a></li>
</ul>
</div>
</div>