Change menu class

0

Good morning. I have the following menu:

<ul>
<li class="active"><a href="?type=0">Ranking PvP</a></li>
<li><a href="?type=2">Ranking Clãs</a></li>
<li><a href="?type=1">Ranking Guilds</a></li>
</ul>

Where'class="active" defines a different color for which flap is open. I would like the user to choose the Clan Ranking for example, change the class from the pvp menu to none and the clan to active. I tried the following but did not succeed:

<script>
$("#li2").click(function(){
$("li1").removeClass("active");
$("li2").addClass("active");
});
</script>
<ul>
<li id="l1" class="active"><a href="?type=0">Ranking PvP</a></li>
<li id="l2"><a href="?type=2">Ranking Clãs</a></li>
<li id="l3"><a href="?type=1">Ranking Guilds</a></li>
</ul>
    
asked by anonymous 29.03.2015 / 15:10

2 answers

1

In a simpler way, you simply put in the click event or whatever you want to remove all active ul classes and only put in this current that is exactly where you clicked, see a example: link

    
29.03.2015 / 15:37
0

You did not specify the selector for the element id, see documentation here :

$("#li1").removeClass("active");
$("#li2").addClass("active");
    
29.03.2015 / 15:22