Home > Enterprise >  How to add on click active class and remove class
How to add on click active class and remove class

Time:12-17

If I click on .m_nice_select then .active_shade will be an additional class active and If I again click on .m_nice_select then will remove the class active from .active_shade

$('.m_nice_select').on('click', function(){
  $('.active_shade').addClass('active');
  $(this).removeClass('active');
});

CodePudding user response:

To toggle the active class on the .active_shade element when the .m_nice_select element is clicked, you can use the toggleClass method like this

$('.m_nice_select').on('click', function(){
  $('.active_shade').toggleClass('active');
});

This will add the active class to .active_shade if it does not have it, and remove it if it does.

Hope I understood that correct and it helps...

  • Related