Sometime we need to add class under some condition on page run time. It is very simple in the jQuery to add the Class on the HTML tag. We can add the class in the HTML tag using jQuery function addClass().
$('TagSelector').addClass('Class-Name');
Let's we make the CSS class with red color and with black background.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style type="text/css">
.my-class{
color:red;
background-color: black;
}
</style>
<button id="mybutton">Click To Add my-class to div</button>
<div id="mydiv">Write Less ,Do More With jQuery</div>
<script>
$("#mybutton").click(function(){
$("#mydiv").addClass('my-class');
});
</script>