Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading