title: dynamically apply active class to nav li
body: <p>I have included a header to my files as in include. In the header is the nav bar. </p>
  
  <p>How do I, using jQuery, apply <code>class="active"</code> to the relevant <code>li</code>. </p>
  
  <p>The only way I could think of doing it is to set a variable on the actual pages, apply an id that is equal to that variable of the relevant page and if function so if they match apply a class to the li. </p>
  
  <p>However, I thought there must be a simpler way of achieving this.</p>
  
  <pre><code>&lt;ul class="nav nav-pills right" id="div"&gt;
      &lt;li id="home" class="active"&gt;
         &lt;a href="index.php"&gt;Home&lt;/a&gt;
      &lt;/li&gt;
      &lt;li id="search"&gt;
         &lt;a href="search.php"&gt;Search&lt;/a&gt;
      &lt;/li&gt;
      &lt;li id="contact"&gt;
        &lt;a href="contact.php"&gt;Contact&lt;/a&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>