title: Bootstrap active class dynamic navigation
body: <p>I am loading nav bar from a HTML file using the <code>load()</code> method. I want the active class for each <code>&lt;li&gt;</code> to change dynamically. I tried many options, but it is not working.</p>
  
  <p>Here is the nav bar code which I saved as <code>navigation.html</code>:</p>
  
  <pre><code>&lt;nav class="navbar navbar-default navbar-fixed-top" role="navigation"&gt;
    &lt;div class="navbar-header"&gt;
      &lt;a class="navbar-brand" href="#"&gt;Theatre Count&lt;/a&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;ul class="nav nav-pills pull-left" id="nav"&gt;
        &lt;li&gt;&lt;a href="home.html"&gt;&lt;span class="glyphicon glyphicon-home"&gt;&lt;/span&gt;&amp;nbsp;Home&lt;/a&gt;&lt;/li&gt;
        &lt;li class="active"&gt;&lt;a href="status.html"&gt;&lt;span class="glyphicon glyphicon-flag"&gt;&lt;/span&gt;&amp;nbsp;Status&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;&lt;span class="glyphicon glyphicon-picture"&gt;&lt;/span&gt;&amp;nbsp;Live Images&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="reports.html"&gt;&lt;span class="glyphicon glyphicon-stats"&gt;&lt;/span&gt;&amp;nbsp;Reports&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;&lt;span class="glyphicon glyphicon-briefcase"&gt;&lt;/span&gt;&amp;nbsp;Archive&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
    &lt;button type="button" class="btn btn-primary pull-right logout"&gt;&lt;span class="glyphicon glyphicon-log-out"&gt;&lt;/span&gt;&amp;nbsp;Log Out&lt;/button&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>Here is my <code>status.html</code> page code:</p>
  
  <pre><code>&lt;body&gt;    
    &lt;script&gt;
      $(document).ready(function(){
          $('#navigation').load('navigation.html');
      });
    &lt;/script&gt; 
    &lt;script&gt; 
      $("#nav li a").on("click", function(){    
          $("#nav li").removeClass("active"); //Remove any previously "active" li
          $(this).closest("li").addClass("active"); //Set click li as active
      });         
    &lt;/script&gt;    
    &lt;div id="navigation"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Here my active class script is not working.</p>