Is there any way to add a new CSS class to an element on :hover
?
Like for jQuery, but translated into CSS:
$(element).addClass('someclass');
To do that, first we create a class and assign it to HTML elements on which we want to apply CSS property. We can use className and classList property in JavaScript. Approach: The className property used to add a class in JavaScript.
New elements can be dynamically created in JavaScript with the help of createElement() method. The attributes of the created element can be set using the setAttribute() method.
Short answer no :)
But you could just use the same CSS for the hover like so:
a:hover, .hoverclass { background:red; }
Maybe if you explain why you need the class added, there may be a better solution?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With