Answers for "add and remove class on click jquery"

1

jquery add remove class clicked element

$(function() {
    $('img').click(function() {
       $(this).toggleClass('active');
    });
});
Posted by: Guest on January-19-2021
3

jquery remove and add class

$( "#foo" ).toggleClass( 'className', addOrRemoveOptional );

//OR
if ($( "#foo" ).hasClass('className')) {
	$( "#foo" ).removeClass( 'className');
} else {
  $( "#foo" ).addClass( 'className');
}
Posted by: Guest on July-01-2020
1

add and remove class in jquery

$('#toggle li').on('click', function () {
    $(this).toggleClass('open')
});
Posted by: Guest on June-04-2020

Code answers related to "add and remove class on click jquery"

Code answers related to "Javascript"

Browse Popular Code Answers by Language