How to add or remove the class of the div using jQuery?

less than 1 minute read

You can add or remove the class of the div in jQuery using the below code snippet,

Example:

<div id="mydiv">Test div</div>
$("#mydiv").addClass('classname');
Result: 
<div id="mydiv" class="classname">Test div</div>
$("#mydiv").removeClass('classname');
Result: 
<div id="mydiv">Test div</div>

Leave a comment