Jquery - addClass() and removeClass()

 addClass() and removeClass() 用来添加CSS效果和删除CSS效果

<html>
<head>
<style type="text/css">
  .highlight { 
  	background:yellow;
  }
 </style>
<script type="text/javascript" src="jquery-1.10.2.js"></script>
</head>
<body>
  <h1>jQuery add / remove css class example</h1>
 
  <p id="para1">This is paragraph 1</p>
  <p>This is paragraph 2</p>
  <p>This is paragraph 3</p>
  <p>This is paragraph 4</p>
 
  <button id="addClass">Add highlight</button>
  <button id="removeClass">Remove highlight</button>
 
<script type="text/javascript">
 
    $("#addClass").click(function () {
 
	  $('#para1').addClass('highlight');
 
    });
 
    $("#removeClass").click(function () {
 
	  $('#para1').removeClass('highlight');
 
    });
 
</script>
</body>
</html>


你可能感兴趣的:(removeClass,addClass)