I would like to add a class to links that contain the variable "activeLink".
The intention is to highlight the currently active link, which means the link that points to where the user currently is.
Here is what I have tried:
//This gets the url parameter
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
var pair;
for (var i=0; i<vars.length; i++) {
pair = vars[i].split("=");
if (pair[0] == variable){
return pair[1];
}
}
return false;
}
//This is where it is stored in variable activeLink
var activeLink = getQueryVariable("pagename");
//This is where I am having trouble
$('.nav a').each(function(index, element) {
if($('.nav a').attr("href") == activeLink) {
$(this).addClass('active');
}
});