Adding and removing classes to/from HTML elements is super-easy with jQuery. Here is a quick tutorial that explains how it’s done. The code snippets are copy & paste friendly, so you can grab, gulp, and go.

jQuery Add Class

Here is the basic technique for adding a class to a specified element:

$('.target-element').addClass('.my-class');

This snippet adds a class named .my-class to the specified target element, .target-element. Here is an example where the class is added when the user clicks a button (i.e., .button):