title: Setting an active menu item based on the current URL with jQuery
body: <p>I want to active menu item on the current URL , now its my HTML :</p>
  
  <pre><code>&lt;ul class="header-tools nav navbar-nav"&gt;
      &lt;li class="mysetting"&gt;  
          &lt;a class="link-menu-active" href=""&gt;first title&lt;/a&gt;
      &lt;/li&gt;
      &lt;li class="mysetting"&gt;
          &lt;a class="link-menu-active" href=""&gt;second title&lt;/a&gt;
      &lt;/li&gt;
      &lt;li class="mysetting"&gt;
          &lt;a class="link-menu-active" href=""&gt;third title&lt;/a&gt;                                     
      &lt;/li&gt;   
  &lt;/ul&gt;
  </code></pre>
  
  <p>and it's my jquery code :</p>
  
  <pre><code>$(".header-tools.nav.navbar-nav li").each(function() {
      var navItem = $(this);
      if( $(navItem).find("a").attr("href") == location.href ) {
           navItem.addClass("active");
      }
  });
  </code></pre>
  
  <p>or it :</p>
  
  <pre><code>var path = window.location.pathname;
  path = path.replace(/\/$/, "");
  path = decodeURIComponent(path);
  
  $(".header-tools.nav.navbar-nav li a").each(function () {
      var href = $(this).attr('href');
      if (path.substring(0, href.length) === href) {
          $(this).closest('li').addClass('active');
      }
  });
  </code></pre>
  
  <p>but none of them doesn't work , what should I do ?</p>
  
  <p>So Thanks</p>