How to add or remove class dynamically in jQuery

By | August 8, 2020
jQuery contains two classes addClass() and removeClass(). By using these classes we can add or remove classes dynamically. addClass() function used to add class and removeClass() function used to remove previously added classes.

For example if i have div tag (id=hiid) and i want to add ‘activeclass’ class then i will add addClass function as below:


And if i need to remove above added class then i will write script as below:


Here is the complete example:

<script src="">script>
 <div id="hiid">This is div tag.div>
<input type="button" name="addclass" id="addclass" value="Add Class" />
<input type="button" name="removeclass" id="removeclass" value="Remove Class" />
<script type="text/javascript">
$("#addclass").click(function () {
$("#removeclass").click(function () {

Leave a Reply

Your email address will not be published. Required fields are marked *