jQuery toggleClass example

Toggle class name on click in jQuery

by amirrahman132132

HTML

<body>
  <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>
</body>

JavaScript

$(document).ready(function(){
  $("p:contains(first)").css("background-color", "yellow");
  $("p:contains(third)").css("background-color", "red");
});

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