jQuery toggleClass() method

The jQuery addClass() method add or remove one or more classes from each element in the set of matched elements, depending on either the class’s presence or the value of the switch argument.

Source Code

<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
 	 .highlight { border : 2px solid #1E8CBE; }
<div class="div1">Div 1</div>
<div>Div 2</div>

<button>Click Here</button>

jQuery("button").click(function () {


Following example toggle the class ‘highlight’ class on div (with class=”div1″) when button is clicked.

Div 1
Div 2


No comments yet.

Leave a Reply