add/remove class dynamically jquery code example
Example 1: jquery remove and add class
$( "#foo" ).toggleClass( 'className', addOrRemoveOptional );
//OR
if ($( "#foo" ).hasClass('className')) {
$( "#foo" ).removeClass( 'className');
} else {
$( "#foo" ).addClass( 'className');
}
Example 2: add and remove class in jquery
$('#toggle li').on('click', function () {
$(this).toggleClass('open')
});