Run
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <style> .mystyle { padding: 30px; margin:5px; background-color: red; color:white; border: 1px solid green; font-size: 20px; } </style> </head> <body> <p>Click the "clickme" button to remove the "mystyle" class from the div element which contain id mydiv:</p> <button id="clickme">click me</button> <div id="mydiv"> This is a DIV element. </div> <script> $(document).ready(function() { $("#clickme").click(function() { if($("#mydiv").hasClass("mystyle")){ $("#mydiv").removeClass("mystyle"); } else { $("#mydiv").addClass("mystyle"); } }); }); </script> </body> </html>