addClass() method in jQuery

addClass() in jQuery

This method is used to add one or more class names to the specified element.

Syntax 1

$(selector).addClass(className)

  • className - Name of one or more space-separated classes to be added.
Syntax 2

$(selector).addClass(function(index,currentClass))

  • index - index position of the element in the set.
  • currentClass - Existing class name(s)

Example 1 - add a class

Try Yourself

Example 2 - add multiple class

Try Yourself

Example 3 - add class with function

Try Yourself