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(func开发者_Python百科tion(){
$(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:(
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.
精彩评论