Вы используете один и тот же идентификатор для каждого раскрывающегося списка; помните, что ID должен быть уникальным. Удалите идентификатор и отправьте выбранный элемент в функцию.
Внутри функции, используйте выбранный элемент, чтобы получить parentNode и найти контейнер по его классу, а затем показать или скрыть с помощью togle()
:
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction(item) {
item.parentNode.querySelector(".dropdown-content").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
/* Dropdown Button */
.dropbtn {
border: 1px dotted !important;
background-color: #1b1b1b;
border-color:white !important;
color: white;
min-width: 500px !important;
font-size: 16px;
cursor: pointer;
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: Black;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
display: inline-block;
position: relative;
z-index: 500 !important;
min-width: 500px !important;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
/* position: absolute !important;
left: 50% !important;
transform: translate(-50%, 0); */
border: 1px solid !important;
border-color: white !important;
background-color: rgba(20,20,21,0.95) !important;
color:#fff;
min-width: 500px;
max-height: 250px !important;
z-index: 500 !important;
overflow-y: scroll !important;
}
/* Links inside the dropdown */
.dropdown-content a {
padding: 8px 16px;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}
<div class="dropdown">
<button onclick="myFunction(this);" class="dropbtn">My Characters</button>
<div class="dropdown-content">
<a>{text}</a>
</div>
</div>
<div class="dropdown">
<button onclick="myFunction(this);" class="dropbtn">My Other Characters</button>
<div class="dropdown-content">
<a>{text}</a>
</div>
</div>