Highlight Active Nav Links On Bootstrap Pages - jQuery Dynamic Menu

Highlight Active Nav Links On Bootstrap Pages - jQuery Dynamic Menu

Dynamic Menu is a jQuery plugin for Bootstrap that automatically adds 'Active' class to navigation items as you navigate between different web pages.

1. Download and insert the JavaScript file dynamic-menu.js into your Bootstrap pages.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="dynamic-menu.js"></script>

2. Call the function dynamicMenu() on the regular Bootstrap navbar and done.

<nav class="navbar navbar-inverse">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      <a class="navbar-brand" href="index.php">Demo</a>
    <div class="collapse navbar-collapse" id="main-navbar">
      <ul class="nav navbar-nav">
        <li><a href="index.html">Home</a></li>
        <li><a href="page-1.html">Page 1</a></li>
        <li><a href="page-2.html">Page 2</a></li>
        <li><a href="page-3.html">Page 3</a></li>
        <li><a href="page-4.html">Page 4</a></li>

3. Override the default styles of 'Active' nav items.

.navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:focus, .navbar-inverse .navbar-nav>.active>a:hover {
  color: #fff;
  background-color: #080808;

This awesome jQuery plugin is developed by Dezento. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 14.12.2017
  • Source