Add active class to menu item
问题 Using Bootstrap 4 v6, I have the following navigation: I'm trying to set the active class on the selected menu item, but nothing I've done has worked. The closest that I've come is with this code: $(document).ready(function() { $('.navbar ul li').click(function(e) { $('.navbar ul li.active').removeClass('active'); var $this = $(this); if (!$this.hasClass('active')) { $this.addClass('active'); } e.preventDefault(); }); }); <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap