0
I managed to solve through Jquery, but wanted a solution only in pure Javascript.
I have a nav
with 4 links on header
, to li
where the usurer is in a class selected
by default, which changes the color and creates a small trace underneath.
My goal is: to happen one hover
in any of the li
's, this class selected
skirt of li
main and go wherever the mouse is.
var navegacaoA = document.querySelector('nav a');
navegacaoA.addEventListener("mouseover", function() {
let navegacaoLi = document.querySelector('nav li');
if (navegacaoLi.classList.contains('selected')) {
navegacaoLi.classList.remove('selected');
this.classList.add('selected');
}
})
<nav>
<ul>
<li class="selected"><span></span><a href="">Invisalign</a></li>
<li><a href="">Benefícios</a></li>
<li><a href="">Serve para mim?</a></li>
<li><a href="">Contato</a></li>
</ul>
</nav>
What is the purpose of this class? Stylization? So why not do it directly by
:hover
of the CSS?– Costamilam