Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
Use querySelectorAll to hide and disable <option> classes

I'm attempting to adapt a solution that I found (here: https://stackoverflow.com/a/2155924/3394918) to a problem I'm having, and can't seem to get it to work. I have several automatically generated menus with select elements that need to change based on user choices. In the linked question above, the user wanted to disable options based on values, however I want to disable (and enable) them based on class. I thought it would be an easy transition, but I haven't been able to figure out what I'm doing wrong.

The original answer:

document.querySelectorAll("#foo option").forEach(opt => {
    if (opt.value == "StackOverflow") {
        opt.disabled = true;
    }
});

What I did with it:

document.querySelectorAll(".models1and2Option").forEach((option) => {
  option.disabled = true;
  option.hidden = true;
});

document.querySelectorAll(".model3Option").forEach((option) => {
  option.disabled = false;
  option.hidden = false;
});

Where each option has a class based on which user choice (model) it corresponds to. Example:

<option class="model3Option" disabled hidden value="Projected Revenue: Incentive Funding">Projected Revenue: Incentive Funding</option>

Not only is nothing changing when I test, when I console.log() document.querySelectorAll(".model3Option") the console says the NodeList is empty (but it's not empty when I test other classes that aren't attached to option elements), so I suspect I have a major error in my assumptions on how the code should be working.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda