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

127
Visualizações
show hide dropdown menu on select change

I have a css code for a navigation menu bar that I just copied.

.sub-header .sub-header-container-menu > li:hover .sub-header-hover-container { 

    display: block; 
}

I'm trying to disable the dropdown or enable it base on the value of my Select object onChange action.

Let's say value is 1:

document.getElementById('sub-header-hover-container').style.display="block";

Let's say value is 2:

document.getElementById('sub-header-hover-container').style.display="none";

But it's not working...

Any ideas will be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

function getValue(selectObject) {
    if (selectObject.value == 1){
        document.getElementById('navBar').style.display="block";
    } else if (selectObject.value == 2){
        document.getElementById('navBar').style.display="none";
    }
}
.sub-header .sub-header-container-menu > li:hover .sub-header-hover-container{
    display: block;
}
<select id="selectValue" onchange="getValue(this)">
    <option value="1" selected>Show</option>
    <option value="2">Hide</option>
</select>
<nav id="navBar" class="sub-header">
    <ul>
        <li>Hi</li>
        <li>Hi</li>
    </ul>
</nav>

You have used "getElementById" with classes. Add an id attribute to the nav bar and set a value to it. Then change the id of "getElementById" to the nav bar's id.

Thanks and best regards!

about 4 years ago · Juan Pablo Isaza Relatório
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