D
D
davc2018-07-05 15:06:55
css
davc, 2018-07-05 15:06:55

After changing css via JavaScript hover doesn't work, what should I do?

Hello, I have an element like this and there is css
<div id="elem"></div>

#elem{
        height: 100px;
        width: 200px;
        background-color: green;
}
#elem:hover{
        background-color: blue;
}

The next question is: When using JavaScript to change the color of an element, after that hover does not work, and this does not only affect the color. When changing any property through javascript, css does not work correctly. What to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
antpv, 2018-07-05
@davc

If you want :hover to override your own styling, use !important in :hover .
For example:

#elem:hover{
        background-color: blue !important;
}

S
Stimulate, 2018-07-05
@Stimulate

https://jsfiddle.net/wmhaxrn3/3/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question