0

Is it possible to add "active" or "inactive" on a menu that uses scrollTo to indicate if the visitor have selected that menu option or not.

Like:

<ul>
 <li><a href="#target1" class="inactive">Target 1</a></li>
 <li><a href="#target2" class="active">Target 2</a></li> <-- selected.
 <li><a href="target3" class="inactive">Target 3</a></li>
...
</ul>
Philip
  • 6,827
  • 13
  • 75
  • 104

2 Answers2

1

Yes you can add the "active" or "inactive" to your class when the link is clicked. On the onclick event of the links, you can use Jquery .addClass() function to add the "active" class and use .removeClass() to remove the "inactive" class

Prabhuram
  • 1,268
  • 9
  • 15
1

you can do it like this i have given your ul an id menu

    $('#menu li a').hover(
  function () {

$(this).addClass('active').removeClass('inactive');
  }, 
  function () {

    $(this).addClass('inactive').removeClass('active');
  }
);

Live Demo OnHover

​if you want to do it on click use this

    $('#menu li a').click(
  function () {

$(this).addClass('active').removeClass('inactive');
      $('#menu li a').not(this).addClass('inactive').removeClass('active');
  }
);

​Live Demo OnClick

rahul
  • 7,573
  • 7
  • 39
  • 53