addclass() method in jquery

This method is used to add the specified class in the particular element. In this example we add multiple class in the element (paragraph).

 $("p").addClass("txtcolor txtxbackground");

Here txtcolor and txtxbackground are classes


Complete Program:

<!DOCTYPE html>
<html>
<head>
  <style>
  p { font-size:26px; }
  .txtcolor { color:red; }
  .txtxbackground { background:Pink; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
 
  <p>Mahak</p>
<script>
  $("p").addClass("txtcolor txtxbackground");
  </script>

</body>
</html>


OUTPUT

1.png