JavaScript jQuery set class active with anchor jquery class active,jquery class active in menu,jquery class

I have a menu like :

<ul>
    <li>
        <a class="scroll-to" target='_blank' href="#one">one</a>
    </li>
    <li>
        <a class="scroll-to" target='_blank' href="#two">two</a>
    </li>
    <li>
        <a class="scroll-to" target='_blank' href="#three">three</a>
    </li>
</ul>

And on my page, multiple anchor like :

<a id="two" target="_blank"></a>

or

<a id="one" target="_blank"></a>

I'm looking for a way to set an active class to my menu when i scroll to an anchor (with click or mouse scroll).

For example if i scroll to my anchor id="two" i need to set active my li #two.

Any ideas ?

Answer:1

If I understand your problem, add your anchors some class, for example section and try this:

$('.section').hover(function() {
  var anchor = $(this).attr('id');

    $('a[target='_blank' href="#'+anchor+'"]').addClass('active');

}, function() {
    $('a').removeClass('active');
});

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

Answer:2

I have a simple JQuery code where I'm trying to get the value of an ASP:HiddenField and display it, but it does not show anything. The hidden field is in the form, not inside any table or div. <...

I have a simple JQuery code where I'm trying to get the value of an ASP:HiddenField and display it, but it does not show anything. The hidden field is in the form, not inside any table or div. <...

  1. value hidden field jquery
  2. value hidden field rails
  3. set value hidden field jquery
  4. get value hidden field jquery
  5. set value hidden field javascript
  6. get value hidden field javascript
  7. change value hidden field jquery
  8. add value hidden field jquery
  9. pass value hidden field javascript
  10. assign value hidden field jquery
  11. javascript value hidden field
  12. set value hidden field jquery asp.net
  13. set value hidden field c#
  14. set value hidden field struts2
  15. add value hidden field javascript
  16. get value hidden field c#
  17. update value hidden field jquery
  18. get value hidden field gridview c#
  19. set value hidden field javascript asp.net
  20. set value hidden field

I've created a html list of buttons/text from an array called items in an .EJS template. How do I pass the specific item's id (item.id) to the button's function so I can send the right data to my api? ...

I've created a html list of buttons/text from an array called items in an .EJS template. How do I pass the specific item's id (item.id) to the button's function so I can send the right data to my api? ...

  1. php pass variable to inline function
  2. javascript pass variable to inline function
  3. jquery pass variable to inline function

I'm trying to count the number of "file" in a JSON object recursively. Here is my function, function totalReports(object, count) { count = count || 0; var key; for(key in object) { ...

I'm trying to count the number of "file" in a JSON object recursively. Here is my function, function totalReports(object, count) { count = count || 0; var key; for(key in object) { ...

I am trying to create a filtering for a Stapes object in RactiveJS, but it seem the two way binding is not responding correctly to the update. I can't work out what is going wrong where as I thought ...

I am trying to create a filtering for a Stapes object in RactiveJS, but it seem the two way binding is not responding correctly to the update. I can't work out what is going wrong where as I thought ...