jquery

Add class to element jQuery

$("div").addClass("hello");

//ADD CLASS ON CLICK
$("button").click(function() {
    $("div").addClass("hello");
});

.addClass() method is used in jQuery to add a CSS class on HTML Element. In the above example, we have added a class named 'hello' on the div element and also on button click.


Was this helpful?