addClass to a href link acccoring to the location.href using jquery
<p>Is there a way to have the following code written more efficiently?</p>

<p>Please note that this section of navigation is part of a CMS and is set to hidden hence you won't see it expanded. I have the following code that works i.e re writes the nav items and adds a class of current according to the location.href but I was hoping it could be written more efficiently?</p>

<p>HTML</p>

<pre><code>    &lt;ul&gt;
      &lt;li&gt;&lt;a class="current" href="#"&gt;&lt;strong&gt;Level 1&lt;/strong&gt;&lt;/a&gt;
        &lt;ul class="sub"&gt;
          &lt;li&gt;&lt;a class="" href="#"&gt;sub level&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a class="" href="#"&gt;sub level&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a class="" href="#"&gt;sub level&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;   
</code></pre>

<p>jQuery</p>

<p>The first part rewrites the hidden section</p>

<pre><code> $(document).ready(function () {
$('menu li:eq(4)').html('&lt;ul&gt;&lt;li&gt;&lt;a href="/level1" class="current"&gt;&lt;strong&gt;level1&lt;/strong&gt;&lt;/a&gt;'
    +'&lt;ul class="sub"&gt;&lt;li&gt;&lt;a href="/sub-level-a" class=""&gt;Sub Level A&lt;/a&gt;&lt;/li&gt;'
    +'&lt;li&gt;&lt;a href="/sub-level-b" class=""&gt;Sub Level B&lt;/a&gt;&lt;/li&gt;'
    +'&lt;li&gt;&lt;a href="/sub-level-c" class=""&gt;Sub Level C&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;');
</code></pre>

<p>});</p>

<p>Adds Class</p>

<pre><code>      $(document).ready(function () {
        if(window.location.href.indexOf("/ucpoolvehicles")!=-1)
                    {
        $("ul.sub li a:eq(0)").addClass("current");
                    } else {

        $("ul.sub li a:eq(0)").removeClass("current");
        }
        if(window.location.href.indexOf("/car-rental")!=-1)
                    {
        $("ul.sub li a:eq(1)").addClass("current");
                    } else {

        $("ul.sub li a:eq(1)").removeClass("current");
        }

        if(window.location.href.indexOf("/private-vehicle-usage")!=-1)
                    {
        $("ul.sub li a:eq(2)").addClass("current");
                    } else {

        $("ul.sub li a:eq(2)").removeClass("current");

        }

        });
</code></pre>

<p>I hope I'm clear in with my instructions
Thanks in advance</p>
