exhtml
12/2/2016 - 6:16 AM

Add class active to current page menu link https://htmlcssphptutorial.wordpress.com/2015/06/30/jquery-automatically-highlight-current-page/


<a class="{{$pages->url}}" href="{{ URL::to('/pages/'.$pages->url) }}">{{ $pages->title }}</a>

<script>

$(function () {

  var curPageSlug = (window.location.pathname.match(/[^\/]+$/)[0]);
  
  // si le queremos agregar la clase 'active' solo al link
  $('.'+curPageSlug).addClass('active');
  
  // si le queremos agregar la clase 'active' al link y al parent
  $('.'+curPageSlug).each(function(){
    $(this).addClass('active');
    $(this).closest('.dropdown').addClass('active');
  });

});

</script>