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:16 pm, vintagetwitch <ksandn...@gmail.com> wrote:
> Hi all,
>
> What I would like to do is add a 'selected' class to a list of navigation
> items based on if the href attribute of the link matches the current page. I
> know I could do this with php, but that's not an option for this particular
> item I'm working on.
>
> The code I have so far is this:
> The alert statements are just there, so I know that my variables are storing
> what I want.
> What I'm stuck on is the conditional statement at the end ------if (hrefs[i]
> == file) {$(this).addClass('selected');}------, how to manipulate the
> matching array item and add the class. The file name is stored in 'file'.
> All the href attributes are in 'hrefs'.
>
>               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) {$(this).addClass('selected');}
>                 }
>
> Thanks, Kevin
> --
> View this message in 
> context:http://www.nabble.com/add-a-%27class%27-to-%3Ca%3E-tag-based-on-page-...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to