labanino
9279
16
Laravel

Adding class .active to current link in Laravel 5.2

Posted 3 years ago by labanino

This is my html:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">My Blog Site</a>
    </div>

    <div class="collapse navbar-collapse navbarCollapse">
        <ul class="nav navbar-nav">
            <li class="active"><a href="{{ route('blogs.index') }}">Blogs</a></li>
            <li><a href="{{ route('blogs.create') }}">Create</a></li>
        </ul>
    </div>
  </div>
</nav>

I have the bootstrap.min.js but the active link it is not working. Then I tried to do the trick with jquery:

$(document).ready(function() {
      $(".nav a").on("click", function(){
      $(".nav").find(".active").removeClass("active");
      $(this).parent().addClass("active");
   });
});

but when I click the link the class .active is added but then it goes away. The jquery works, I'm not sure if in Laravel is done different. Thanks.

Please sign in or create an account to participate in this conversation.