Setting active class for navigation
<p>I have a separate navigation php which has a list of links and menu options:</p>

<pre><code> echo "&lt;ul id='menu'&gt;";
//some if loop to do the following:
    echo "&lt;li&gt;&lt;a href='#'&gt;Adminstration&lt;/a&gt;
                    &lt;ul&gt;&lt;li&gt;";
            if($userm == 'R'||$userm == 'RW') {
                echo "&lt;a href='/N.Jain/administration/usermanagement.php&gt;User Management&lt;/a&gt;";
                }
</code></pre>

<p>This file has 10 such sub-menu. What i am trying to achieve here is that if a User is on this particular page, then the menu should expand and highlight that option.</p>

<p>Here is my menu javascript:</p>

<pre><code>function initMenu() {
  $('#menu ul').hide();
  $('#menu li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) &amp;&amp; (checkElement.is(':visible'))) {
        $('#menu ul:visible').slideUp('normal');
        return false;
        }
      if((checkElement.is('ul')) &amp;&amp; (!checkElement.is(':visible'))) {
        $('#menu ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
</code></pre>

<p>Now i am trying to get the link and then set its class to active and then do something: </p>

<pre><code>function markActiveLink() {
 $("#menu li ul li a").filter(function() {
  var currentURL = window.location.toString().split("/");
  return $(this).attr("href") == currentURL[currentURL.length-1];
 }).addClass("active");

if($('#menu li ul li a').hasClass('active') == true) {
    console.log('has');
 }
}
</code></pre>
