title: jQuery Menu Removing Class when Clicking Back Button
body: <p>I have a jQuery menu that isn't working like it should when you click the back button. There is a class of "selected" in html for the link of the page that you are currently on. jQuery removes the class and adds the class "hovering" when you hover over other links. The problem is that when you click the back button the class of "selected" remains on the link you just visited instead of for the link of the page you are actually on. I am a newbie but I am assuming that the html is overwritten.</p>
  
  <p>So far I've tested it only on FF, IE and Chrome. This problem is only encountered on FF. I was wondering if there is a way in to revert back to the original CSS class in the html.
  The menu can be tested <a href="http://www.accustarappraisals.com/accustar-complete/accustar-new/index.html" rel="nofollow">here</a>.</p>
  
  <p>Here is the html:</p>
  
  <pre><code>&lt;div id="menu"&gt;
  
  &lt;ul&gt;
  
  &lt;li id="menuitem0" class="selected"&gt;&lt;a href="index.html"&gt;HOME&lt;/a&gt;&lt;/li&gt;
  &lt;li id="menuitem1"&gt;&lt;a href="link1.html"&gt;Link1&lt;/a&gt;&lt;/li&gt;
  &lt;li id="menuitem2"&gt;&lt;a href="link2.html"&gt;Link2&lt;/a&gt;&lt;/li&gt;
  &lt;li id="menuitem3"&gt;&lt;a href="link3.html"&gt;Link3&lt;/a&gt;&lt;/li&gt;
  &lt;li id="menuitem4"&gt;&lt;a href="link4.html"&gt;Link4&lt;/a&gt;&lt;/li&gt;
  &lt;li id="menuitem5"&gt;&lt;a href="link5.html"&gt;Link5&lt;/a&gt;&lt;/li&gt;
  &lt;li id="menuitem6"&gt;&lt;a href="link6.html"&gt;Link6&lt;/a&gt;&lt;/li&gt;
  
  &lt;/ul&gt;
  
  &lt;/div&gt;&lt;!--menu--&gt;
  </code></pre>
  
  <p>Here is the jQuery code:</p>
  
  <pre><code>jQuery(document).ready(function($) {
  jQuery(function($){
        var pathmatch = location.pathname.match(/([^\/]+)$/);
        // set selected by the current pathname, or default to Home...
        if( !pathmatch || !$('#menu a[href$="' + pathmatch[1] + '"]').addClass('selected').length){
          $('#menu a').eq(0).addClass('selected');
        }
        $('#menu a')
          .hover(function(ev){
            // add (or remove) 'hovering' class to the parent LI and its parent UL...
            $(this).parent().parent().andSelf().toggleClass('hovering',ev.type==='mouseenter');
          })
        });
  
  });
  </code></pre>