I have this addEventListener that suppose to work when I click the options in my nav-bar but is not working and Chrome is telling me that child.addEventListener is not a function.

I already tried to switch the addEventListener use a call function instead of an anonymous one.

MY JS CODE :

var child = document.getElementsByClassName("nav-link");

child.addEventListener("click", function() {
   child.style.color = "#C23314"; 
});

MY HTML CODE :

<ul class="navbar-nav ml-auto">
    <li class="nav-item">
        <a class="nav-link" id= "inicio" href="#">Inicio</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#">Productos</a>
        <li class="nav-item">
        <a class="nav-link" href="#">Acerca</a>
    </li>
</ul>

Just want that the link changes color when i click on it.

0 Answers