Highlight navigation using location.pathname

Hi All,
I’m attempting to get a nav system in place that will highlight the current nav item based on full path.

The <li> of the menu item matching the current page should have the class “selected” attached to it.

I’m just having zero joy and I’ve been at it all weekend.

Any assistance is greatly appreciated.

 $(function(){
   var path = window.location.pathname;
   if ( path )
     $('#sidebar_content a[@href$="' + path + '"]').parents('li').attr('class', 'selected');
 });

<style>
.selected {
	font-weight:bold;
}
</style>
<ul id="sidebar_content">
  <li><a href="/news/index.html">News</a></li>
  <li><a href="/other/index.html">Articles</a></li>
</ul>

@ was removed in jQuery 1.3
Just remove it and it should work.

But, you might consider a different approach. If you’re url happens to have certain characters in it, it might confuse the jquery selector parser. I would use either filter() or each() and manually do that tail matching on the href.

My code works fine.
I just forgot to link to the JQuery library…

I blame the 43° temp yesterday.