simple jQuery addClass() doesn't seem to be working
<p>I want to be able to determine what page the user is currently on. a simple indicator in the form of adding unique style to the navigation link the user is currently viewing its context</p>

<p>here is my script, all selectors working fine, if statement also do the job, but the addClass() function does nothing.. here is my code: </p>

<pre><code>&lt;script&gt;
$(document).ready(function(){
    var pathname = window.location.pathname;
    $("#links ul li a").each( function() {
        var href= $(this).attr("href");
        if (pathname.indexOf(href) &gt;= 0){
            $(this).addClass("active");
        }
    } );
});
&lt;/script&gt;


    &lt;nav id="links"&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a&gt;About&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/nav&gt;
</code></pre>

<p>HTML :</p>

<p>got it to work ,this is my finaly code, is there a need for any improvments ? </p>

<pre><code>$(document).ready(function(){
    var pathname = window.location.pathname;
    var onDomain=true;
    $("#links ul li a").each( function() {
        var href= $(this).attr("href");
        if (href != undefined &amp;&amp; pathname.indexOf(href) &gt;= 0){
            $(this).addClass("active");
            onDomain=false;
        }
    });
    if (onDomain){
        $("#links ul li:first-child a").addClass("active");
    }
});
</code></pre>
