[jQuery] trying to add a 'class' to a link based on the value of the link's href
Hi there,
What I'm trying to do as add a 'selected' class to the current page
navigation link. I want to cycle through all the page links and if
'file' matches 'hrefs', add the class accordingly. Specifically, I'm
having problems with the last part of code below ---if (hrefs[i] ==
file) {$(this).addClass('selected');}---. I can't seem to isolate the
matching link.
I no javascript pro, so I'm probably approaching this all wrong.
My code is below. The alerts are just there to make sure the variables
are storing the values I want.
var file = jQuery.url.attr("file");
alert(file);
var hrefs = new Array();
$('.design_html_nav li').each(function(){
hrefs.push($(this).find('a').attr('href'));
});
alert (hrefs[6]);
for(i=0;i<hrefs.length;i++)
{
if (hrefs[i] == file) {$('.design_html_nav li a').addClass
('selected');}
}
Thanks, Kevin