What is the addclass() method in jQuery?

The addClass() method adds one or more class names to selected HTML elements. This method helps with changing the CSS properties of these HTML elements at a later stage. However, it does not remove existing class attributes; instead, it adds only one or more class names to the existing class attribute.

Syntax

svg viewer

Code

The following example​ demonstrates the use of the addclass() function. Upon clicking the button, the newclass class gets assigned to it, thus, changing the button’s CSS properties.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved