As a newcomer to coding, I'm trying to figure out how to create multiple dropdown menus where each one collapses when you click outside of it. I've been struggling with the code I wrote for weeks now - I want to have 3 dropdown menus but only one is working properly. Can someone help me fix this issue? Thank you in advance!
HTML Code
<div class="container">
<a href="#home"><span class="Agencymenu">Home</span></a>
<a href="#news"><span class="Agencymenu">News</span></a>
<div class="dropdown">
<button class="dropbtn" onclick="myFunction()">Team 1</button>
<div class="dropdown-content" id="myDropdown">
<a href="#"><span class="Agencymenu">Link 1</span></a>
<a href="#"><span class="Agencymenu">Link 2</span></a>
<a href="#"><span class="Agencymenu">Link 3</span></a>
</div>
</div>
<div class="dropdown2">
<button class="dropbtn2" onclick="myFunction2()">Team 2</button>
<div class="dropdown-content2" id="myDropdown2">
<a href="#"><span class="Agencymenu">Link 1</span></a>
<a href="#"><span class="Agencymenu">Link 2</span></a>
<a href="#"><span class="Agencymenu">Link 3</span></a>
</div>
</div>
</div>
CSS Code
(Same as original)
JS Code:
(Same as original)