Thanks a bunch for that link, Brian. I really did search the documentation,
and I feel crazy for missing that rather obvious link from the XPath
section.

I ended up going the less-than-elegant route and breaking out of jQuery to
use the JS match() function, but it works nicely:

        if (location.pathname.substring(1)) {
                $('#main_nav').find('a').each(
                function() {
                        if(location.pathname.match( $(this).attr('href') ) )
                                $(this).parent().attr('id', 'current');
                        
                });
        }


Cheers!

dd


Citrus wrote:
> 
> Darius,
> 
> $= means "attribute ends with".  Check out
> http://jquery.com/docs/Base/Expression/CSS/ , the "Supported, but
> different" section.
> 
> Taking a close look at the selection documentation might also help you
> with item #2 a bit.
> 
> You're going to have to figure out how to text-match your relative URL
> with the absolute URL that will be in location.pathname using plain old
> regular expressions.
> 
> Keep in mind that IE automatically converts relative URLs to absolute ones
> in memory, while the other browsers don't.  This may affect your results.
> 
> - Brian
> 
> 
>> So I have a tabbed navigation system, and I am using jquery to
>> auto-select the current tab.
>> Here's the html:
>>
>>
>> <ul id="main_nav">
>>   <li> /services/ SERVICES </li>
>>   <li> /store/ STORE </li>
>>   <li> /about-us/ ABOUT US </li>
>>   <li> /gallery/ GALLERY </li>
>>   <li> /press/ PRESS </li>
>> </ul>
>>
>>
>> Here's my jQuery code (adapted from
>> http://leftlogic.com/info/articles?id=1):
>>
>>
>> if (location.pathname.substring(1)) {
>>    $('#main_nav [EMAIL PROTECTED]"' + location.pathname.substring(1) +
>> '"]').parent().attr('id', 'current');
>> }
>>
>> I'm using parent() so that the id gets applied to the 'li' element and
>> not the 'a' element.
>>
>> All of this works. However, I'm unclear about a couple of things:
>>
>> First, why is the dollar sign $ necessary in the xpath statement? i've
>> seen no documentation on it, and when i try it without the dollar sign,
>> it doesnt work.
>>
>> Second, Sometimes I have a url like: /about-us/4/3 and my jQuery
>> statement fails because the href != location.pathname.
>> How can i rewrite this statement so that it searches for the href value
>> in the location.pathname value and applies the id to the matching
>> string?
>>
>> Thanks in advance,
>> dd
>> --
>> View this message in context:
>> http://www.nabble.com/Xpath-and-tab-selection-tf2563069.html#a7143657
>> Sent from the JQuery mailing list archive at Nabble.com.
>>
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
> 
> 
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Xpath-and-tab-selection-tf2563069.html#a7145094
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to