jQuery > Attribute related method

.toggleClass() - Toggle class attribute in jQuery

How to toggle the class attribute value of an element in jQuery?


To toggle (add/remove) css class of an html element, toggleClass() method can be used.

 <script>
       $("#btnToggleClass").click(function () {
           $("#div2").toggleClass("class1");
       });
  </script>

Above code will toggle class “class1” to the element whose id is “div2” on the button (whose id is “btnToggleClass”) click event.

 Views: 6239 | Post Order: 37



Write for us






Hosting Recommendations