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'); }); 

http://codepen.io/tomekbuszewski/pen/mwmwok


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -