Thanks for your response, and my apologies for the double post. So now, this is what I have, and for some reason, now I'm not able to extract any values from the array of <a> tags, even with an alert. Don't I need to loop through them to see if 'a === file'.
var file = jQuery.url.attr("file"); alert(file); $('.design_html_nav li').each(function(){ var a = $(this).find('a').attr('href'); if(a.href===file){ a.addClass('selected'); } }); cheers On Mar 11, 6:14 pm, mkmanning <michaell...@gmail.com> wrote: > Deja Vu :) > > Why use a separate array? > $('.design_html_nav li').each(function(){ > var a = $(this).find('a').attr('href'); > if(a[0].href===file){ > a.addClass('selected'); > } > > }); > > On Mar 11, 3:36 pm, ksandn...@gmail.com wrote: > > > 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