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

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -