Sometimes we faced the problem of toggling the class in html because of only by changing the classes can do a different action in html.
Toggle class means exchange the class names. We can toggle class using jQuery as follows:
1 2 3 4 5 6 7 8 | $(document).ready(function(){ if($('#id').hasClass('active')) $('#id').removeClass('active').addClass('deactive'); else $('#id').removeClass('deactive').addClass('active'); }) |
OR toggle class using jQuery may be achieved through writing like that also
1 2 3 4 5 | $(document).ready(function(){ $('#id').toggleClass('active','deactive'); }) |