Javascript Trick: Add a class or ID to an HTML element on hover

Here is the line of code you can use to add a class or ID to an element in your webpage when a user hovers over it (for example: if you want to add a class called “active” to an li element with a class called “top-nav” in the div called “menu” when a user hovers over it):

  • Recent Posts

  • Recent Comments

  • Categories

  • Archives