Easy Tutorial
❮ Misc Deferred Notifywith Index ❯

jQuery addClass() Method

jQuery HTML/CSS Methods

Example

Add a class name to the first <p> element:

$("button").click(function(){
    $("p:first").addClass("intro");
});

Definition and Usage

The addClass() method adds one or more class names to the selected elements.

This method does not remove existing class attributes, it only adds one or more class names to the class attribute.

Tip: To add multiple classes, separate the class names with spaces.


Syntax

Parameter Description
classname Required. Specifies one or more class names to be added.
function( index,currentclass) Optional. Specifies a function that returns one or more class names to be added. index - Returns the index position of the element in the set.<br><br>currentclass - Returns the current class name of the selected element.

More Examples

Add Two Classes to an Element

Add Class Using a Function

Change an Element's Class Name


jQuery HTML/CSS Methods

❮ Misc Deferred Notifywith Index ❯