Languages
[Edit]
EN

jQuery - remove class from div

6 points
Created by:
chelsea
626

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

Quick solution:

$("#my-element").removeClass("my-class-2");

Full code example:

// ONLINE-RUNNER:browser;


<!doctype html>
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 <style>
   .my-class-1 { border: 2px solid red; padding: 5px; width: 200px; }
   .my-class-2 { background: yellow; }
 </style>
 <script>
   
   $(document).ready(function() {
     $("#my-button").click(function() {
       // HERE:
       $("#my-element").removeClass("my-class-2");
     });
   });
   
   </script>
</head>
<body>
 <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>
</body>
</html>

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

jQuery

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join