0
Can i change element:hover using javascript?
5 Réponses
+ 5
yes actually js has hover event but that's not css
it is by
element.onmouseover=change();
element.onmouseout=change();
function change(){
element.classList.toggle("hover");
}just add the things in class called hover and it adds and remove the class from the element.
many jqueryui uses event based thing instead of css which has limited functions.
you can see different codes here too.
in my code too I coded a menu that uses this you can see it.
+ 3
No, unfortunaly...
But you can get around, with css classes: define your different behaviour of hover rules on different classes identifiers ( names ), and with JS you can modify the element class attribut...
( remember that this attribut may contains several classes names in a string, each separate by a space character to treat correctly it ;) )
+ 2
@Sandeep Chatterjee:
You're totally right. I've reflex to maximize css use and minimize js use :P
+ 2
yes, onmouseover event helps you
+ 1
yes it is good practise to move things to css instead of script