For adding a class to an element in jQuery, the .addClass() method is used, which dynamically sets one or more CSS classes for elements. It is handy when you want to change styles, animations, or states without directly using inline CSS.
Syntax:
$(selector).addClass("className");
Example:
Suppose you have a div with an ID called box, and you would like to add a class called highlight when a button is clicked. You can use:
$("#myButton").click(function() {
$("box").addClass("highlight");
});