开发者

Highlight current page in menu

I would like to highlight the current page in the sidebar menu. I am using the f开发者_JAVA技巧oll. jquery script to do this. When I test the jquery script in the console window in firebug, it works.

When I upload the script to the website http://depts.washington.edu/uwbg/gardens/horticulture.php, it does not highlight the current page (except for a couple of pages). I've looked at similar postings on this forum, but could not figure out a solution that worked for my site. Any help appreciated. Thanks.

$(document).ready( function () {
var path = location.pathname;
if ( path )
 $('#section_navigation ul li a[href$="' + path + '"]').attr('class', 'current');
 }); 


When the above script is executed the menu which you are populating via an ajax call has not completed. Therefore the selector matches no elements. Put the code above in the callback of your menu ajax function (inside jquery_loadSectionNav.js) and it should work better!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜