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-file-name-tp22463734s27240p22463734.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to