I'm trying to get the textContent of a a tag inside an ul tags. The problem is that when I access the console returns me "null" instead of the element. I don't know what I am doing wrong. Hope you ca help me and thanks.
On other hand, the console returns me HTMLColletion but I can't get anything from there because I don't know the syntax to get the things from there, all I get is "undefined".
<div class="dropdown">
<ul class="navbar-nav mr-auto ">
<li class="nav-item">
<a id="resumen" class="nav-link dropdown-toggle" href="#" data-toggle="dropdown"> Productos 0 | Precio 0€ </a>
<ul id="productos" class="dropdown-menu">
</ul>
</li>
</ul>
</div>
The JS:
var resumen2 = document.getElementsByClassName("nav-link dropdown-toggle");
var resumen = document.getElementById("resumen");
console.log(resumen);
console.log(resumen2.textContent);
document.getElementById("resumen").textContent? You don't need to grab the elements by class and the element by id if the element with the id is the one you want.