Simulate hover using JavaScript events

前端 未结 4 1832
渐次进展
渐次进展 2021-01-05 22:26

Is it possible to simulate hover using JavaScript Events? I tried injecting mouseover event on the target element but no luck.

For example, if there is a link that

4条回答
  •  情歌与酒
    2021-01-05 23:06

    Yes, you would simply add onMouseOver and onMouseOut events to the element in question

    Like this:

    Then make your javascript change the element's class (if you want two different CSS classes) or simply modify the element's style directly. You could do something like this.

    
    

    Please note that you can also use a library like jQuery to handle this even more simply.

提交回复
热议问题