0

Can i change element:hover using javascript?

25th Dec 2016, 1:57 PM
Emil Tsvetanov
Emil Tsvetanov - avatar
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.
25th Dec 2016, 2:15 PM
Sandeep Chatterjee
+ 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 ;) )
25th Dec 2016, 2:04 PM
visph
visph - avatar
+ 2
@Sandeep Chatterjee: You're totally right. I've reflex to maximize css use and minimize js use :P
25th Dec 2016, 2:20 PM
visph
visph - avatar
+ 2
yes, onmouseover event helps you
29th Dec 2016, 2:58 PM
Naveen DA
Naveen DA - avatar
+ 1
yes it is good practise to move things to css instead of script
25th Dec 2016, 2:21 PM
Sandeep Chatterjee