Hello everyone, I'm attempting to change the background color of a specific link in my navigation bar to a different color when the user is on the corresponding page. Here's the code snippet I've been trying to use:
$("#nav li ul li a #changeBG1").css("background-color","red");
Here is a snippet of the HTML for the navigation bar:
<ul id="nav">
<li><a href="index.php">home</a></li>
<li><a href="custHelp.php">who we are</a>
<ul>
<li id="changeBG1"><a href="about.php">about</a></li>
<li id="changeBG2"><a href="help.php">team</a></li>
</ul>
</li>
Unfortunately, this code changes all links with the ID "changeBG1" in the navigation bar instead of just the one I want. I'm struggling to figure out how to target only that specific link within the navigation bar.
Here is the JQuery code I have so far:
var url = window.location.href;
url = url.substr(url.lastIndexOf("/") + 1);
$("#theNav").find("a[href='" + url + "']").addClass("theNavsBG");
if (url == 'about.php'){
$("#nav li ul li a #changeBG1").css("background-color","red");
}
Any assistance would be greatly appreciated. Thank you!