Add class to parent LI where A = current document?
<p>I'm trying to append a class to an LI automatically if the filename matches the href (e.g; if the anchor has the href attribute set to about.php and the filename of the current page is about.php then it would append the class.) however, along the way I've hit some complications and I've been getting myself confused with the syntax a little...</p>

<p>So far I have this...</p>

<pre><code>var filename = location.pathname.substring(1)

$(document).ready(function(){
    $('a').each(function() {
        if (this.href === filename) {
            $(this).parent('li').addClass('current_page_item');
        }
    });
});
</code></pre>

<p>My navigation is constructed as shown <a href="http://jsfiddle.net/sgySp/3/" rel="nofollow">here</a> and as you can see, it works and everything but only when the class is set manually... so I'm trying to get it to be automatic from the actual filename.</p>

<p>I hope this make some sense to someone, as I'm really confused on how to get this working now!</p>

<p>Thank-you to anyone who contributes, it's of great help and will help me understand the jquery syntax further, actually selecting something specific and writing a logical statement in jquery really confuses me as it's very different to PHP, which is what I'm used to.</p>

<p>My markup looks like this, since I didn't include it before and just <em>assumed</em> people would look at the source code to understand what I was meaning (though, I should have put it here)</p>

<pre><code>&lt;nav&gt;
    &lt;div class="container"&gt;
        &lt;ul class="group" id="effects"&gt;
            &lt;li&gt;&lt;a href="index.php" title="View the latest news"&gt;News&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="about.php" title="Find out more about us"&gt;About&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#" title="Find out about races"&gt;Races&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#" title="Find out what tools we use"&gt;Tools&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#" title="Read the Frequently Asked Questions"&gt;FAQ&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="contactus.php" title="Contact us"&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/nav&gt;
</code></pre>

<p>Thanks.</p>
