Remove class

Description

The following code shows how to add and remove class in click event handler.

Example


<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style type="text/css">
.changeP {<!--  w ww . j a  va 2  s.c  o m-->
  font-weight: bold;
  color: red;
}
</style>

<script type="text/javascript">
  $(document).ready(function() {
    $("input.buttonA").click(function() {
      $("p.fifthparagraph").addClass("changeP");
    });
    $("input.buttonB").click(function() {
      $("p.fifthparagraph").removeClass("changeP");
    });

  });
</script>
</head>
<body>
  <input type="button" value="Change" class="buttonA" />
  <input type="button" value="Change" class="buttonB" />
  <div style="background: #eee;" class="contentToChange">
    <h2>Header 2</h2>
    <p class="firstparagraph">java2s.com</p>

    <p class="fifthparagraph">java2s.com</p>

  </div>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities