I have the following html for 3 dropdown checklists (The anchor span is clicked to make the unnumbered list visible)
for (var checkList of document.querySelectorAll('.dropdown-check-list')) { 
   checkList.getElementsByClassName('anchor')[0].onclick = function(evt) {
   if (checkList.classList.contains('visible'))
      checkList.classList.remove('visible');
   else
      checkList.classList.add('visible');
   }
}.dropdown-check-list {
  display: inline-block;
}
.dropdown-check-list .anchor {
  margin-top: 6px;
  width: 357px;
  position: relative;
  cursor: pointer;
  display: inline-block;
  padding: 5px 50px 5px 10px;
  border: 1px solid #ccc;
}   
.dropdown-check-list ul.items {
  padding: 2px;
  display: none;
  margin: 0;
  border: 1px solid #ccc;
  border-top: none;
}
.dropdown-check-list.visible .items {
  display: block;
}<div id="list1" class="dropdown-check-list" tabindex="100">
  <span class="anchor">Expired Metadata<span class="count">20</span></span>
  <ul class="items"> ... </ul>
</div>
<div id="list2" class="dropdown-check-list" tabindex="100">
  <span class="anchor">Unregistered Groups<span class="count">20</span></span>
  <ul class="items"> ... </ul>
</div>
<div id="list3" class="dropdown-check-list" tabindex="100">
  <span class="anchor">Unregistered Teams<span class="count">20</span></span>
  <ul class="items"> ... </ul>
</div>However, when I click any of the anchor spans it only opens the last list (div.list3). The spans do not correspond to the correct list. Is there any way to fix this?
 
     
     
     
    