← Back to Index

.addClass()

Adds the specified class(es) to each element in the set of matched elements.

Examples

1. Add a single class

$('div').addClass('active');

Result

<div class="active"></div>

2. Add multiple classes

$('p').addClass('highlight bold text-center');

Result

<p class="highlight bold text-center"></p>

3. Chaining

$('span').addClass('visible').text('Hello');

Result

<span class="visible">Hello</span>

Parameters

Parameter Type Description
className string One or more space-separated classes to be added to the class attribute of each matched element.

Returns: The original SR object for chaining.