jQuery remove active class

jQuery remove active class

HTML
<ul class="menu">
   <li class="active"><a href="#">Home</a></li>
   <li><a href="#">About</a></li>
   <li><a href="#">Contact</a></li>
   <li><a href="#">Gallery</a></li>
</ul>
CSS
 ul {
     list-style: none;
 }

 ul li { 
   margin: 10px 0px;
   padding: 15px;
   text-align: center;   
 }

 ul li a {
    color: #587aaf;
    text-transform: uppercase;
   
 }

.active {
    background: #9bd0eb;
}
Javascript
  $('.menu').on('click', 'li', function() {
    $('.menu li.active').removeClass('active');
    $(this).addClass('active');
});
1,786 Views
78146cookie-checkjQuery remove active class

Leave a Reply

Your email address will not be published. Required fields are marked *