-1

as many of us I'm really new to JS and I'm trying to create sort of a filter to select diferent people from different cities and based on their carreer. So im trying to create two dropdown menus with a selector to achieve this. Here is my noob code for it.

window.onload = function() {

  var atencion = document.getElementById("working_place");
  var especialidad = document.getElementById("area");
 
  if (atencion === "remote" && especialidad === "medic") {
    document.querySelectorAll(".santiago",".concepcion" ".psique" ".nutri" ".trainer").style.display = "none";
  }
 };
<div>
  <div>
    Know all the team <select id="working_place">
      <option value="all">All the team</option>
      <option value="remote">Remote</option>
      <option value="santiago">Santiago</option>
      <option value="concepcion">Concepción</option>
    </select><select name="especialidad" id="area">
      <option value="medic">Doctor</option>
      <option value="psique">Psique</option>
      <option value="nutri">Nutricionist</option>
      <option value="psico">Psicologyst / Life Coach</option>
      <option value="trainer">Personal Trainer</option>
    </select>
  </div>
</div>
<h1>Specialist</h1>
<div class="medic santiago">Doctor</div>
<div class="psique santiago">Psique</div>
<div class="nutri remote">Nutricionist</div>
<div class="trainer concepcion">Personal Trainer</div>

Thanks for the help.

1 Answers1

2

document.querySelectorAll can aggregate multiple classes, but they need to be together, comma separated like you would in CSS. That returns an HTML collection, which you can iterate through like an array using forEach

if (atencion === "remote" && especialidad === "medic") {
  document.querySelectorAll(".santiago, .concepcion, .psique, .nutri, .trainer").forEach(el => el.style.display = "none");
}
Kinglish
  • 23,358
  • 3
  • 22
  • 43