I have a main navigation but I need to apply the class of 'current' to the <li>
if it matches the URL I have specified it should.
This is what I have:
$(function() {
var url = location.pathname;
if(url.indexOf('girls')) {
$("li#nav-01").addClass('current');
}
if(url.indexOf('boys')) {
$("li#nav-02").addClass('current');
}
if(url.indexOf('capes')) {
$("li#nav-03").addClass('current');
}
if(url.indexOf('about_us')) {
$("li#nav-04").addClass('current');
}
if(url.indexOf('contact')) {
$("li#nav-05").addClass('current');
}
if(url.indexOf('frequently_asked_questions')) {
$("li#nav-06").addClass('current');
}
});
and then
<div id="nav-main">
<ul class="navmain">
<li id="nav-01" class=""><a href="../girls/">Girls</a></li>
<li id="nav-02" class=""><a href="../boys/">Boys</a></li>
<li id="nav-03" class=""><a href="../capes/">Accessories</a></li>
...
</ul>
</div>
This doesn't seem to work so What I am looking for is something that allows me to put the full URL up to a certain directory.
So where I have.
'if(url.indexOf...'
I'd like to have something along the lines of:
'if(url=http://www.siteaddress/directory/...'
So then if the current URL is '.../directoryname/' then the <li>
I have specified should be selected ('current') depending on that URL, is.
Thanks for reading.