i need to highlight the current page in navbar.!!its work!! but i extends new html page the navigation bar can't show ????

13 views
Skip to first unread message

varun kishore Ravi

unread,
Feb 13, 2018, 7:33:10 AM2/13/18
to Django users
<div>
  <nav>
    <ul class="nav">
      <li class="active"><a href="{% url 'dashboard' %}">DASHBOARD</a></li>
      <li><a href="#">EVENT</a></li>
      <li><a href="#">LOBBIES</a></li>
      <li><a href="#">MARKET</a></li>
      <li><a href="#">ONLINE PLAYERS</a></li>
      <li><a href="#">SUBSCRIBE</a></li>
    </ul>
  </nav>
</div>

<script type="text/javascript">
$(function () {
    setNavigation();
});

function setNavigation() {
    var path = window.location.pathname;
    path = path.replace(/\/$/, "");
    path = decodeURIComponent(path);

    $(".nav a").each(function () {
        var href = $(this).attr('href');
        if (path.substring(0, href.length) === href) {
            $(this).closest('li').addClass('active');
        }
    });
}    
</script>
Reply all
Reply to author
Forward
0 new messages