jQuery menu active link

Posted by antosha on Stack Overflow See other posts from Stack Overflow or by antosha
Published on 2010-03-26T03:46:18Z Indexed on 2010/03/26 3:53 UTC
Read the original article Hit count: 396

Filed under:
|
|
|
|

Hello, I am trying to make a jquery menu that when I click on one of the links (without reloading the page), it changes its class to "active" and removes this class when I click on another link.

here is my code :

<script type="text/javascript">
$(document).ready(function() {
  $(".buttons").children().("a").click(function() {
    $(".buttons").children().toggleClass("selected").siblings().removeClass("selected");
  });
});
</script>


  <ul class="buttons">
    <li><a class="button" href="#">Link1</a></li>
    <li><a class="button" href="#">Link2</a></li>
    <li><a class="button" href="#">Link3</a></li>
    <li><a class="button" href="#">Link4</a></li>
  </ul>

Can someone tell me why my code is not working and how to fix it? Thanks :)

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about menu