0

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

here is my code :

enter code here`$(document).ready(function(){

$(function(){
  $("a").click(function(){
    $(this).parent().addClass('inny').siblings().removeClass('inny');
  });
});
});




 <ul id="mainMenu">
        <li class="hover-width1"><a href="d.html">STRONA GŁÓWNA</a></li>
        <li class="hover-width3"><a href="glowna.html">OFERTA</a></li>
        <li class="hover-width3"><a href="d2.html">CENNIK</a></li>
        <li class="hover-width2"><a href="tom.html">PRZEPISY</a></li>
        <li class="hover-width2"><a href="jan.html">GALERIA</a></li>
        <li class="hover-width1"><a href="#">NASI KLIENCI</a></li>
        <li class="hover-width2"><a href="#">NARZĘDZIA</a></li>
        <li class="hover-width1"><a href="#">CIEKAWOSTKI</a></li>
        <li class="hover-width2"><a href="#">KONTAKT</a></li>
      </ul>

Can someone tell me why my code is not working when I reload the page:(

2
  • what do you mean by "when I reload the page"? Commented Aug 22, 2011 at 10:21
  • This mean: When I click for any link Commented Aug 22, 2011 at 10:53

1 Answer 1

1

You can use $(document).ready(function(){ or $(function(){ to init jquery code, but not both at the same time.

$(function(){
  $("a").click(function(){
    $(this).parent().addClass('inny').siblings().removeClass('inny');
  });
});

The code should work fine, and when you reload the page the markup changes won't stay up, so you must make use of the uri / cookies to determine what item to show active.

Sign up to request clarification or add additional context in comments.

1 Comment

Please tell me what can I do it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.