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

146
Visualizações
How to disable classList on only hover and not styling

nxt_question_btn.classList.remove('btns')
.btns{
    margin-top: 10px;
    float: right;
    height: 30px;
    background-color: lightblue;
    border: none;
    outline: none;
    cursor: pointer;
    width: 110px;
}
.btns:hover{
    border: 1px solid black;
    box-shadow: 2px 1px 5px lightblue;
}
        <button id="next" class="btns">Next Question</button>
        <button id="end" class="btns">End Quiz</button>

I want to disable the hover option when the button is disabled, my Javascript currently disbles the styling and the hover option. How can I target the hover only?

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

0

Use the :not() pseudo class to only apply the hover style when the button does not have the disabled attribute.

.btns{
    margin-top: 10px;
    float: right;
    height: 30px;
    background-color: lightblue;
    border: none;
    outline: none;
    cursor: pointer;
    width: 110px;
}
.btns:not([disabled]):hover{
    border: 1px solid black;
    box-shadow: 2px 1px 5px lightblue;
}
<button id="next" class="btns">Next Question</button>
        <button id="end" class="btns" disabled>End Quiz</button>

Alternatively, you can also use the CSS disabled pseudo class as the selector.

about 4 years ago · Juan Pablo Isaza Relatório

0

I also want to mention that if you already have a style for :disabled, you can add the hover state to it:

.btns {
  margin-top: 10px;
  float: right;
  height: 30px;
  background-color: lightblue;
  border: none;
  outline: none;
  cursor: pointer;
  width: 110px;
}

.btns:hover {
  border: 1px solid black;
  box-shadow: 2px 1px 5px lightblue;
}

.btns:disabled, .btns:disabled:hover {
  border: lightgray;
  box-shadow: none;
  cursor: no-drop;
}
<button id="next" class="btns">Next Question</button>
<button id="end" class="btns" disabled>End Quiz</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