I need to check the previous page URL a user has visited for a string, then apply an "active" class to an "a" tag on the current page using jQuery.
e.g. if a user's previous page url contains "new-york" and looks like - "www.domain.com/new-york/", then on the current page I want to check for an "a" tag which contains "new-york" in the link, then add a class to this tag. I have about 20 different cities I need to check and add classes too.
Here is what code I have so far...
$("#cities a").each(function () {
if ($(this).attr("href") == document.referrer) {
$(this).addClass("active");
}
});
I know document.referrer is the exact URL, how do I grab/check for a string from document.referrer?
Thanks