jquery - highlight main menu item when sub item is open -
in web site have menu bar drop down menus of items. when viewing 1 of sub-pages want parent item in menu bar highlighted (class='active
).
here code:
<div id="sidebar-left"> <div class="menu"> <ul class="listeohne"> <li class="color1" id='active'><a href="index.php">startseite</a> </li> <li class="color2"><a href="">wer wir sind</a> <ul> <li class="whiteback"> <a href="werwirsind.php">einführung</a> </li> <li class="whiteback"><a href="statuten.php">statuten</a> </li> <li class="whiteback"><a href="vorstand.php">vorstand </a> </li> <li class="whiteback borderbottomgrey"><a href="pdf/organigramm_svnw_13.pdf">organisation </a> </li> </ul> </li>
view example site www.nzz.ch. site www.svnw.ch.
i have tried numerous solutions described in forum, none of them works me, not expert.
get link of page 1 :
var pathname = window.location.pathname;
or
$(location).attr('href');
via get current url in javascript?
then search in menu having href equal "pathname" , add ".active" class!
$('a[href$="abc"]'). $(function(){ var actlink = $(location).attr('href'); $('a[href$="actlink"]').parent("li").addclass('active'); })
or
$(function(){ var actlink = $(location).attr('href'); $('ul > li > a[href$="actlink"]').parent("li").addclass('active'); });
don't know sure works. haven't tested it!
Comments
Post a Comment