0
When I click a button I want it to be marked white, if I click another uncheck the old and leave the new marked
var menu = document.querySelectorAll("#menu > ul > li > a");
for(var i = 0; i < menu.length; i++){
menu[i].addEventListener("click", configMenu);
}
function configMenu(){
for(var i = 0; i < menu.length; i++){
menu[i].style.background = "#469c17";
}
this.style.background = "white";
}
#menu{
width: 100%;
height: 36px;
background-color: #469c17;
}
#posts_menu{
margin-left: 39px;
}
#posts_menu, #chat_menu, #agenda_menu, #arquivo_menu{
line-height: 36px;
float: left;
list-style: none;
}
#posts_menu a, #chat_menu a, #agenda_menu a, #arquivo_menu a{
display: block;
width: 100px;
text-align: center;
background-color: #469c17;
text-decoration: none;
color: black;
}
#posts_menu a:hover, #chat_menu a:hover, #agenda_menu a:hover, #arquivo_menu a:hover{
background-color: white;
}
<div id="menu">
<ul>
<li id="posts_menu"><a href="post">Todos Posts</a></li>
<li id="chat_menu"><a href="chat">Chat</a></li>
<li id="agenda_menu"><a href="#">Agenda</a></li>
<li id="arquivo_menu"><a href="arquivos">Arquivos</a></li>
</ul>
</div>
There are two ID’s in the tags. Try to give a brief explanation of what has changed and how you solved the problem
– Phelipe
@Phelipe I’m doing this :D, but that two ids?
– Julio Henrique
He had two Ids, but he’s already pulled.
– Phelipe
Julio but if I put the link (my site is in mvc) it updates the page and does not appear!! only works with #
– AKU
@Is AKU using any back-end language? because in this case it would be interesting to put or not the active class if it is on the page corresponding to the link
– Julio Henrique