jQuery toggleClass()

jQuery toggleClass() method add or remove one or more classes from each matched element.

jQuery toggleClass() method checks each element for the specified class names.This method add class to the element if missing , and removed if already added.

Syntax

jQuery.toggleClass(className)

Add Class in p element using jQuery.

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery toggleClass() Example </title>
<style type="text/css">
.myClass{
    color: LawnGreen;
  } 
</style>
</head>
<p class="myClass" >Hello, Friends how are you ? </p>
<input type="button" value="Toggle Class" id="toggleClass">
</html>
Javascript
$(document).ready(function(){
$("#toggleClass").click(function () {
$("p").toggleClass( "myClass" ); 
});
});