Jquery removing and adding active class to li nodes & issues with preventDefault
<p>Jquery Removing &amp; Adding 'Active' Class On LI Navigation Works With preventDefault, But Link No Longer</p>

<p>Jquery removing an adding active class to li nodes not working</p>

<p>I know it should be really basic to remove and add the active class to li's in order to highlight the current page's nav item, but I've been unable to get it to work.</p>

<p>I find that I must use e.preventDefault() to make it work, but when I do the link doesn't work but the highlighted nav item works. If I remove the preventDefault() then it navigates but doesn't highlight. I should say that my nav is sitting in a header.php include file. Here's what I have:</p>

<pre><code>&lt;ul class="myNav"&gt;
  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="portfolio.php"&gt;Portfolio&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="about.php"&gt;About&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="contact.php"&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

$('.myNav li a').click(function (e)
{
  e.preventDefault();
$('.myNav li').siblings().removeClass('active');
$(this).parent().addClass('active');
//var url = $(this).attr("href"); 
//window.location = url;
});
</code></pre>

<p>I tried to send the page to the clicked url and this loads the correct page, but it removes the class! I'd like to solve this, but I'd also like to understand why it isn't working correctly.</p>
