jQuery - click event to add and remove active class

0 votes
267 views
added Apr 17, 2019 in jQuery by LC Marshal Captain (25,790 points)
$('.floating-menu').click(function () {
    $('.floating-menu').removeClass('active');
    $(this).addClass('active');  // use this to add class instead
});

 

CSS

.floating-menu {
  text-align: center;
  padding: 12px;
  border-bottom: 1px dotted #000;
  font-size: 1.2rem;
  &:hover, &.active {
    background: $award19-color;
  }
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...