javascript - jQuery set class active with anchor -
i have menu :
<ul> <li> <a class="scroll-to" href="#one">one</a> </li> <li> <a class="scroll-to" href="#two">two</a> </li> <li> <a class="scroll-to" href="#three">three</a> </li> </ul> and on page, multiple anchor :
<a id="two" target="_blank"></a> or
<a id="one" target="_blank"></a> i'm looking way set active class menu when scroll anchor (with click or mouse scroll).
for example if scroll anchor id="two" need set active li #two.
any ideas ?
if understand problem, add anchors class, example section , try this:
$('.section').hover(function() { var anchor = $(this).attr('id'); $('a[href="#'+anchor+'"]').addclass('active'); }, function() { $('a').removeclass('active'); });
Comments
Post a Comment