cssaddclass

How do I add a new class to an element dynamically?


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');

Solution

  • 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?