Looking to compare the URL of a current page to an element in the navigation bar using jQuery.
Started by assigning the current URL to a variable:
var currentPage = window.location.href;
Then utilized an .each
function to loop through each item in the navigation bar:
$("nav ul li a").each(
function() {
}
);
Now, trying to figure out what to compare the URL to from the list within an if statement:
if(currentPage === ????) {};
Goal is to highlight the page currently being visited in the navigation bar by changing its background image with CSS once the jQuery identifies the match. This is a task assigned in a jQuery class.
Despite searching, struggling to find a solution that matches this specific issue. Any insights would be greatly appreciated!
Still grappling with how to phrase this question, hoping for some clarity and guidance on how to achieve this desired functionality.