使用Jquery在导航菜单中突出显示父链接

我正在使用以下Jquery来突出显示导航中当前页面的链接。

// Add Active Class To Current Link var url = window.location; // get current URL $('#nav a[href="'+url+'"]').addClass('active'); 

我的导航看起来像这样:

  

导航具有“关于我们”部分的子视图。

我想让“关于我们”链接接收“活动”类,这样当我在其子查询页面上时它会保持突出显示。

因此,例如,如果我在“子链接2”页面上,则“关于我们”链接将被赋予活动类。

任何人都能指出我在正确的方向吗?

谢谢你的帮助

试试下面的代码,

 // Add Active Class To Current Link var url = window.location; // get current URL $('#nav a[href="'+url+'"]').addClass('active'); var $activeUL = $('.active').closest('ul'); /* Revise below condition that tests if .active is a submenu */ if($activeUL.attr('id') != 'nav') { //check if it is submenu $activeUL .parent() //This should return the li .children('a') //The childrens are  and 
    .addClass('active'); //add class active to the a }