jQuery addClass()
The jQuery addClass()
method is used to add one or more CSS classes to an HTML element. It can help you to style your webpage dynamically by changing the appearance of an element based on a user interaction or a specific event.
Syntax
The addClass()
method takes one or more parameters, which represent the classes you want to add to the selected element. Here is the syntax:
$(selector).addClass(class1, class2, ...);
Use
The addClass()
method is used to modify the CSS classes of an element based on a specific condition. You can use jQuery to add classes dynamically to HTML elements, such as buttons, forms, or menus, based on user interactions or specific events.
For example, you can add a class to a button to change its text color when a user hovers over it, or add a class to a form to change its background color when it is submitted successfully.
Example
Here is an example of using addClass()
to modify the class of an HTML element: