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

122
Visualizações
Make a dropdown to show with click instead of hover

I am trying to add a function onclick for my dropdown menu, so instead of showing when I hover, I want it to show when I click on it, do you know what can I do?

My dropdown is on the grid icon next to "Images"

This is my repo so you can view my code: https://github.com/Diefonro/HTML-CSS

You can also see the page displayed right now at: https://diefonro.github.io/HTML-CSS

Thank you

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

0

you have to implement the below function and call it on the onclick event. and as @Tom suggested you need to get rid of the below part also from the style sheet

.dd-cont:hover .drop-d {
   display: block;
}

this is how we catch specific element which has particular class and we can change styles of the elements like below

function clickDD() {
    const dropdown = document.querySelector('.drop-d');
  dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block';
}

here is a working example(jsFiddle) from your code

ps I did not included any assets to the fiddle

about 4 years ago · Juan Pablo Isaza Relatório

0

To handle the click event, you can take a look at EventListener or onclick attribute.

The dropdown is shown on hover because of this CSS rule :

.dd-cont:hover .drop-d {
   display: block;
}
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