jQuery - remove class from div

6 points
Created by:

In this article we can see how to dynamically remove one class from div element using jQuery.

Quick solution:


Full code example:

// ONLINE-RUNNER:browser;

<!doctype html>
 <script src=""></script>
   .my-class-1 { border: 2px solid red; padding: 5px; width: 200px; }
   .my-class-2 { background: yellow; }
   $(document).ready(function() {
     $("#my-button").click(function() {
       // HERE:
 <div id="my-element" class="my-class-1 my-class-2">Some text</div>
 <button id="my-button" style="margin-top: 20px;">Remove class</button>


Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.