jQuery toggleClass()
toggle class
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/*ww w . j a v a2 s.com*/ <script> $(document).ready(function(){ $("button").click(function(){ $("p").toggleClass("main"); }); }); </script> <style> .main { font-size: 120%; color: red; } </style> </head> <body> <p>This is a paragraph.</p> <p class="main">This is another paragraph.</p> <button>Toggle class "main" for p elements</button> </body> </html>