Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger CSS "hover state" using Javascript? [duplicate]

CSS's "hovered state" will trigger when the user hovers over an element:

<style> .element{  } .element:hover{     background-color:red; } </style> 

How can we set the element to "hovered state" using Javascript?

Is it possible?

like image 719
Pacerier Avatar asked Jun 20 '11 05:06

Pacerier


People also ask

How do you force a hover state?

Right-click your element. Choose "Force element state" and then the state you want (e.g. :hover) Dance.

How do I make hover affect another element?

If you have two elements in your HTML and you want to :hover over one and target a style change in the other the two elements must be directly related--parents, children or siblings. This means that the two elements either must be one inside the other or must both be contained within the same larger element.

How can use hover state in CSS?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.


1 Answers

You're probably better off duplicating the :hover styles into another class and then just adding that class name to the element when you want them to change permanently. Pseudo-classes are "pseudo" for a reason.

like image 132
Scott Avatar answered Sep 23 '22 18:09

Scott