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

218
Visualizações
Disable W3.CSS Hover Dropdown

I have the typical W3.CSS hover dropdown, but I want it disabled until ready:

<div id="A" class="w3-dropdown-hover" style="width: 100%;">
    <button id="B" disabled class="w3-button" style="width: 100%;">Hover To Open</button>
    <div id="C" class="w3-dropdown-content w3-bar-block w3-border" style="width: 100%;">
        <p>2B</p>
        <p>|| !2B</p>
    </div>
</div>

As you can see I have put the disabled on the button and it looks disabled as you would expect.

But the dropdown still appears when I hover. I do not want that. I only want the dropdown to open when the button is not disabled.

You obviously cannot put the disabled on C, because the disabled only works on things like buttons, inputs, etc.

Where do I put the disabled?

When I am ready in my javascript, how do I remove/reapply the disabled? By that I mean, on which of "A", "B" or "C" do I apply the jQuery $("#A_Letter").prop('disabled', false);

Edit: the only thing I can think of is put disabled on the button and momentarily change the class of "A" to w3-dropdown-click.

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

0

I'd apply some css to 'disable' the pointer events so your browser won't detect any hover actions:

<div id="A" class="w3-dropdown-hover" style="width: 100%; pointer-events: none;">

Demo Snippet:

<link href="https://cdnjs.cloudflare.com/ajax/libs/w3-css/4.1.0/w3.css" rel="stylesheet"/>
<div id="A" class="w3-dropdown-hover" style="width: 100%; pointer-events: none;">
    <button id="B" disabled class="w3-button" style="width: 100%;">Hover To Open</button>
    <div id="C" class="w3-dropdown-content w3-bar-block w3-border" style="width: 100%;">
        <p>2B</p>
        <p>|| !2B</p>
    </div>
</div>


When I am ready in my javascript, how do I remove/reapply the disabled

For the automatically toggling both states, we can:

  • Move the pointer-events:none to a CSS class so we can use toggleClass()
  • Use the prop to toggle the disabled state

function toggle() {
  $("#A").toggleClass('disabled-hover');
  $('#B').prop('disabled', (i, v) => !v);
}
.disabled-hover {
  pointer-events: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/w3-css/4.1.0/w3.css" rel="stylesheet"/>
<div id="A" class="w3-dropdown-hover disabled-hover" style="width: 100%;">
    <button id="B" disabled class="w3-button" style="width: 100%;">Hover To Open</button>
    <div id="C" class="w3-dropdown-content w3-bar-block w3-border" style="width: 100%;">
        <p>2B</p>
        <p>|| !2B</p>
    </div>
</div>

<button onclick='toggle()'>Toggle Disabled</button>

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