0

I am trying to keep a background image for active link and hover for a navigational bar on this site

Sitelink: http://67.23.226.231/~edutubei/onepage/#about

using below code

$(document).ready(function() {
  $('#navigation a[href^="#' + location.pathname.split("#")[1] + '"]').addClass('current'); 
}); 

with the below css

ul.navigation .current{
  background:url(../images/current_page.png) no-repeat right bottom;
}    
ul.navigation .current a, ul.navigation .current a:hover{
  color:#FFF;
}

but this is not working how can i keep a background image/highlight the active and hover links

4

1 回答 1

0

你的选择器不对。它应该是 '.navigation' 代替 '#navigation'

location.pathname 仅返回 /~edutubei/onepage/。所以你必须改用 window.location.href 。

 $('.navigation a[href="#' + window.location.href.split("#")[1] + '"]').addClass('current');
于 2013-04-05T19:22:26.527 回答