jQuery toggleClass example

Toggle class name on click in jQuery

HTML

<p>I'm the first sentence.</p>
<p>I'm the second sentence.</p>
<p>I'm the third sentence.</p>
<p>I'm the fourth sentence.</p>

CSS

.first { font-style: italic }
.third { text-decoration:underline }

JavaScript

$(document).ready(function(){
  if ($("p:contains(first)"))
  	$("body").addClass("first")
  if ($("p:contains(third)"))
  	$("body").addClass("third")
});

//$(document.body).addClass('first');
//$(document.body).addClass('third');