if statement syntax in Javascript jQuery .each function
<p>(very new to JavaScript jQuery)</p>

<p>Can an if statement contain a collection of other functions, specifically .each functions? If yes, is there something wrong with my implementation? </p>

<pre><code>var string2 = "domain";
var mainpath = (window.location.href);

if (mainpath.indexOf(string2))  {

    $("#topnav a").each(function(){                         
        var thishref = $(this).attr('href');    
        $(this).attr({href: thishref + '?lnkid=tnav'}); 
    });

    $("#nav a").each(function(){                            
        var thishref = $(this).attr('href');    
        $(this).attr({href: thishref + '?lnkid=pnav'});
    });

}
</code></pre>

<p>What I want to do is run the code inside the if statement only when the page is at my domain (rather than inside the development space of a cms).
-Thanks</p>
